Link to home
Start Free TrialLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

asked on

Move to First Row in a DataSet

Is it possible to MOVE to the First Row in a DataSet?

If this is the first row:  DataSet1.Tables(0).Rows(0)   . . .
how do I get the dataset to "move" there?

this didn't work:
DataSet1.Tables(0).Select("DataSet1.Tables(0).Rows(0)")
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wtconway
wtconway

As far as I know you don't really MOVE to that row. You can declare an object of that row. You can even just reference it like so:

DataSet1.Tables(0).Rows(0)

What context are you trying to do this in?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeMCSD

ASKER

thanks all . .
what I'm trying to do is delete the current row, then add a row, then continue
looping through the current dataset:

For Each row In DataSet1.Tables(0).Rows
     .....
     row.Delete()
     DataSet1.Tables(0).Rows.Add(row1)
     
Next    <<<<<<<<<  get an error when I try to move to the next row . .
                                so I need to move the row up or something . . .  
Or if you know the name of the column:

DataSet1.Tables(0).Rows(0)("ColumnName").ToString()

that's generally how I use it.

But if you are setting the column's value to a variable, make sure you check for null first. It's a bit different in ADO.NET:

If DataSet1.Tables(0).Rows(0).IsNull("ColumnName") = False Then
   myVar = DataSet1.Tables(0).Rows(0)("ColumnName").ToString()
End If
The reason you're getting the error is because you're attempting to loop through the rows collection but you're changing the collection when you delete a row. So .NET throws up that error letting you know you can't do that. I got around this my moving the rows that I didn't want to delete to another datatable. Then using that datatable as my final copy.
wt . . would you have a sample of the that code?  thanks
Why you can't just delete all unnecessary rows first and then to add the same qty of the new rows?
I may have a sample somewhere on EE. Let me search for it.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll have to come back to this one . . thanks all