none
There is no row at position xx? RRS feed

  • Question

  • I used the following code to retrieve rows in a remote database table and saved in a dataset, then loop through the rows in the dataset table to do some work, the code in running in a windows service every 1 minites, but occasionally some exception throwed out, the error message is "There is no row at position xx.", it seems like for some reason, the rows in the dataset table are lost, can anyone give me some suggestion?

     

    Code Snippet

    'Populate dataset

    If Not PopulateDataset() Then Return
    'Get the table row count in the dataset

    Dim transferCount As Integer = mDsStageDB.Tables(mInControlTable).Rows.Count

     

    If transferCount > 0 Then

    Dim inTransact As TableInTransact

    'Loop throught the rows in the dataset table

    For i As Integer = 0 To transferCount - 1
              inTransact = New TableInTransact
              inTransact.Load(mDsStageDB.Tables(mInControlTable).Rows(i))
              inTransact.ProcessInTransact()

    'Some other code

    Next

    End if

     

     

    The exception is throwed from the highlighted line.

     

    thanks

    Friday, September 21, 2007 6:09 PM

Answers

  • Are you running Visual Studio 2008 beta 2? This may be a bug that was fixed in a patch that is released with Visual Studio 2008 Beta 2 (and will be released independently at RTM).

     

    The other option, which is a better solution from a performance standpoint, is to use a for each statement instead a for loop. The performance of the For Each statement is better with a DataTable, and you will avoid the problem that you are running into. Let me know if this fixes your problem.

     

    Thanks,

    Erick

    Monday, September 24, 2007 4:26 PM
  • That makes sense. However, try changing your For loop into For Each loop, and see if the problem persists.

     

    Thanks,

    Erick 

     

    Monday, September 24, 2007 4:35 PM

All replies

  • Is it possible code deletes rows in a mInControlTable while it is still in a loop?

     

    Monday, September 24, 2007 10:56 AM
    Moderator
  • Are you running Visual Studio 2008 beta 2? This may be a bug that was fixed in a patch that is released with Visual Studio 2008 Beta 2 (and will be released independently at RTM).

     

    The other option, which is a better solution from a performance standpoint, is to use a for each statement instead a for loop. The performance of the For Each statement is better with a DataTable, and you will avoid the problem that you are running into. Let me know if this fixes your problem.

     

    Thanks,

    Erick

    Monday, September 24, 2007 4:26 PM
  • No, The code only read the data in the row and use that as the key to retrieve data from other tables.

     

    Monday, September 24, 2007 4:32 PM
  • I am running visual studio 2005.

    I am trying the for each statement now, I will let you know if it works. It normally takes one or two days for an exception poped out when I used the for loop.

    thanks,

    Monday, September 24, 2007 4:35 PM
  • That makes sense. However, try changing your For loop into For Each loop, and see if the problem persists.

     

    Thanks,

    Erick 

     

    Monday, September 24, 2007 4:35 PM
  • After changing the for loop to for each loop, no exception occured for one day, so I think it solved the problem. But I am still wondering why the for loop did not work?

     

    Tuesday, September 25, 2007 5:56 PM
  • I'm glad to hear that this worked.

     

    There was a bug in DataSet that caused this problem. The bug has been fixed in Visual Studio 2008 (and will be fixed in a patch for VS 2005 as well).

     

    Thanks,

    Erick

    Tuesday, September 25, 2007 7:11 PM