MikeMCSD
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)")
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(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Ad d(row1)
Next <<<<<<<<< get an error when I try to move to the next row . .
so I need to move the row up or something . . .
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.Ad
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) ("ColumnNa me").ToStr ing()
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("C olumnName" ) = False Then
myVar = DataSet1.Tables(0).Rows(0) ("ColumnNa me").ToStr ing()
End If
DataSet1.Tables(0).Rows(0)
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)
myVar = DataSet1.Tables(0).Rows(0)
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll have to come back to this one . . thanks all
DataSet1.Tables(0).Rows(0)
What context are you trying to do this in?