Results 1 to 7 of 7

Thread: there is no row at position error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    92

    there is no row at position error

    I have a pretty extensive code and need a little guidance on one item:

    All works well until I want to add a record by using the 'add record' button.
    As soon as I do this I get a message 'there is no row at position xx' on record load

    I suspect it is because I am doing calculations on each record (under the Sub StartCalcs) as they load and since the new record has no data yet the calculations are erroring out and thus the error as listed above.

    My question is how do I stop the form from attempting to do calcs until data is present or is this even the actual issue? Is there something I can add to the AddNew button that prevents the error. I am at a lose here as to what to try as I have tried various ways to avoid this yet it is persistent.

    My Load code is as follows:

    Code:
     Private Sub Load_Info_Form(sender As Object, e As EventArgs) Handles MyBase.Load
            LoadForm = True
            Fuel_TableTableAdapter.Fill(Fuel.Fuel_Table)
            Load_Info_TableTableAdapter.Fill(LoadInfoDataSet.Load_Info_Table)
    
            'Loads last record onto form
            LoadInfoDataSetBindingSource.Position = LoadInfoDataSet.Load_Info_Table.Rows.Count - 1
    
            'Setting Default Values
            LoadInfoDataSet.Load_Info_Table.Columns("ACT_MILES_DIFF_CALC").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("ACTUAL_DH_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("ACTUAL_LOADED_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("ADJUSTED_MILEAGE").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("AGENT_EMAIL").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("AGENT_FEE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("AGENT_NAME").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("AGENT_PHONE").DefaultValue = "(000) 000-0000"
            LoadInfoDataSet.Load_Info_Table.Columns("ACT_MILES_DIFF_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("ARRIVE_TIME_01").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("ARRIVE_TIME_90").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("ARRIVE_EARLY").DefaultValue = " NO"
            LoadInfoDataSet.Load_Info_Table.Columns("AVG_DISCOUNT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("BOBTAIL_AUTH").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("BOL").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("BOL_WEIGHT").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("BROKER_AGENCY").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("BROKER_FINES").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("CAPACITY").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("CARRIER_LOAD_NUMBER").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("CARRIER_LOADED_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("CARRIER_DH_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("CLAIM").DefaultValue = "NO"
            LoadInfoDataSet.Load_Info_Table.Columns("CLAIM_AMOUNT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("COST_PER_MILE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("DATE_PAID").DefaultValue = DateTime.Now
            LoadInfoDataSet.Load_Info_Table.Columns("DEF_GALS_TOT").DefaultValue = "0.000"
            LoadInfoDataSet.Load_Info_Table.Columns("DEF_PURCHASED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("DEPART_TIME_01").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("DEPART_TIME_90").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("DETENTION_OVERRIDE_01").DefaultValue = "False"
            LoadInfoDataSet.Load_Info_Table.Columns("DETENTION_OVERRIDE_90").DefaultValue = "False"
            LoadInfoDataSet.Load_Info_Table.Columns("DETENTION_OWED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("DETENTION_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("DH_MILES_DIFF_CALC").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("DOCK_TIME_01").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("DOCK_TIME_90").DefaultValue = "00:00"
            LoadInfoDataSet.Load_Info_Table.Columns("DRIVER_COUNT").DefaultValue = "SLSC"
            LoadInfoDataSet.Load_Info_Table.Columns("DROP_CONFIRM").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("DROPPED_EARLY").DefaultValue = " NO"
            LoadInfoDataSet.Load_Info_Table.Columns("DROP_LOCATION").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("EQUIP_WASHING_COST").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("EQUIP_WASH_REIMBURSE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("EXTRA_PAY_RECEIVED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("EXTRA_STOP_PICKUP_PAY").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("EXPENSES_TOTAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FAX_COST").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FAX_REIMBURSEMENT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_CARD_FEE_TOTAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FS_DIFF1_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FS_DIFF2_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FSA_DIFF1_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FSA_DIFF2_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_CARD_FEE_TOTAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_COST_AVG").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_PROFIT_LOSS").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_PURCHASED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_REIMBURSE_TOTAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_ADJ_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_ADJ_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("FUEL_SUR_ADJ_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("GALS_PURCHASED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("INVOICE_NUMBER").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("LAYOVER_TONU").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LH_DIFF1_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LH_DIFF2_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LINEHAUL_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LINEHAUL_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LINEHAUL_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_LOCKS").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_LOCK_REIMBURSE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_ISSUE").DefaultValue = " NO"
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_RELAY_OFF").DefaultValue = "--"
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_RELAY_ON").DefaultValue = "--"
            LoadInfoDataSet.Load_Info_Table.Columns("LOAD_RELAY_TRUCK").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("LUMPER_FEES").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("LUMPER_REIMBURSEMENT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("MULTI_STOP").DefaultValue = " NO"
            LoadInfoDataSet.Load_Info_Table.Columns("OSD").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("OUT_OF_POCKET_FUEL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("OUT_OF_ROUTE_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("PARKING").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PALLET_COUNT").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("PALLET_EXCHANGE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PALLET_EXCHANGE_REIMBURSE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PER_MILE_RATE_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PER_MILE_RATE_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PER_MILE_RATE_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PIECE_COUNT").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("PM_DIFF1_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PM_DIFF2_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PRODUCT").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("PROFIT_GRAND_TOTAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PROFIT_PER_MILE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PU_CONFIRM").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("PU_DRP_TRLR_FEE").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("PU_NUMBER").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("RATE_ACTUAL").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RATE_NEGOTIATED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REEFER_PURCHASED").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REEFER_REIMBURSEMENT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REEFER_FUEL_LVL").DefaultValue = "FULL"
            LoadInfoDataSet.Load_Info_Table.Columns("REEFER_FUEL_PROFIT_LOSS").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REPAIR_COSTS").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REPAIR_CREDIT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REV_TOTAL_DIFF").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REV_TOTAL_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REV_TOTAL_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("REV_TOTAL_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RF_DIFF1_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RF_DIFF2_CALC").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RFR_FUEL_SUR_FAX").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RFR_FUEL_SUR_PAID").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RFR_FUEL_SUR_TRUCK").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RFR_GALS_TOT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("RFER_FUEL_TAX_REFUND").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("SCALE_WEIGHT").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("SCALES_COST").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("SCALES_REIMBURMENT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("SEAL").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TOLL_COST").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("TOLL_REIMBURMENT").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("TOTAL_DRIVEN_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("TOTAL_MILES_DIFF_CALC").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("TRACTOR_FUEL_TAX_REFUND").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("TRAILER_DROPPED_01").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TRAILER_DROPPED_90").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TRAILER_HOOKED_01").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TRAILER_HOOKED_90").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TRANSFLO_NUMBER").DefaultValue = "NO TRANSFLO - EMAILED"
            LoadInfoDataSet.Load_Info_Table.Columns("TRANSFLO_DATE_TIME").DefaultValue = "N / A"
            LoadInfoDataSet.Load_Info_Table.Columns("TRIP_MPG").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("TRIP_END_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("TRIP_START_MILES").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("TRLR_SHUTTLE_PAY").DefaultValue = 0
            LoadInfoDataSet.Load_Info_Table.Columns("TRUCK_FUEL_PROFIT_LOSS").DefaultValue = 0D
            LoadInfoDataSet.Load_Info_Table.Columns("TRUCK_SUPPLIES").DefaultValue = 0D
    
            DV = New DataView(LoadInfoDataSet.Load_Info_Table)
    
            'check if Near Due or Expired Dates
            MedCertExpire()
            StateMiles()
            ELogs()
            FranchiseTax()
            AnnualReports()
            HVU2290()
            IFTAdue()
            TrkRegdue()
            TrkInspdue()
            TrlInspdue()
            MCS150due()
            NewYear()
            EOYReports()
            StartCalcs()
    
            LoadForm = False
        End Sub
    
        Private Sub StartCalcs()
            Select Case True
                Case LoadForm = True
                    Exit Sub
                Case LoadForm = False
                    ImportTotals()
                    LoadResp()
                    BrokerEmail()
                    Detention01()
                    LoadProfit()
                    LoadIssue()
            End Select
        End Sub

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,861

    Re: there is no row at position error

    Perhaps you could actually tell us where in this extensive code the exception is thrown. Regardless, if you want to perform an action only if a condition is true then you use an If statement for that.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    92

    Re: there is no row at position error

    This is the exception:

    Event Type Moniker Event Time Duration Thread
    Activated Historical Code Context Exception thrown: 'System.IndexOutOfRangeException' in System.Data.dll ("There is no row at position 1092.") Exception thrown: 'System.IndexOutOfRangeException' in System.Data.dll ("There is no row at position 1092.") Hyperlink: Activate Historical Debugging 27.06s [11508] Main Thread

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,861

    Re: there is no row at position error

    I repeat:
    Quote Originally Posted by jmcilhinney View Post
    Perhaps you could actually tell us where in this extensive code the exception is thrown.
    At a quick glance, I don't see anywhere in the code you actually posted that that exception could be thrown. We shouldn't have to spend our time trying to work out stuff that you already do or should know and can tell us. If you're asking about an exception, where that exception is thrown is fundamental to the question so it should be obvious that you need to provide that information. I'm guessing that it's in one of those methods that you're calling at the bottom of the code but we shouldn't have to guess and you haven't provided the code for those methods anyway.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,861

    Re: there is no row at position error

    Also, I'm not sure if maybe you have changed the code to simplify things for this thread but, if it's what you're actually using, this part is ridiculous:
    vb.net Code:
    1. Select Case True
    2.     Case LoadForm = True
    3.         Exit Sub
    4.     Case LoadForm = False
    5.         ImportTotals()
    6.         LoadResp()
    7.         BrokerEmail()
    8.         Detention01()
    9.         LoadProfit()
    10.         LoadIssue()
    11. End Select
    That code is functionally equivalent to this:
    vb.net Code:
    1. If Not LoadForm Then
    2.     ImportTotals()
    3.     LoadResp()
    4.     BrokerEmail()
    5.     Detention01()
    6.     LoadProfit()
    7.     LoadIssue()
    8. End If
    Alternatively, if you want to reduce nesting:
    vb.net Code:
    1. If LoadForm Then Return
    2.  
    3. ImportTotals()
    4. LoadResp()
    5. BrokerEmail()
    6. Detention01()
    7. LoadProfit()
    8. LoadIssue()
    Also, LoadForm is a bad name for a field. That name is more appropriate for a method that loads a form. For the apparent purpose of that field, loadingForm or isLoading would be more appropriate names.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,906

    Re: there is no row at position error

    When you click your Add Record, where does it Add? A new row in a dgv? Or something else?
    The easiest way I can see is to set your LoadForm variable (which JM told you to rename) to true until you’ve populated your row

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    92

    Re: there is no row at position error

    Quote Originally Posted by .paul. View Post
    When you click your Add Record, where does it Add? A new row in a dgv? Or something else?
    It adds it to a DT.

    Quote Originally Posted by .paul. View Post
    The easiest way I can see is to set your LoadForm variable (which JM told you to rename) to true until you’ve populated your row
    This is exactly what I am attempting to do yet all my attempted 'solutions' have failed. I am not exactly sure where to turn the LoadForm (renamed to isLoading) to TRUE when adding a new record. I have tried adding
    Code:
    isLoading = true
    in the 'AddNew' section of the code but it appears to skip right over it via debug.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width