Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

step trough an dataset and sort stuff out

Status
Not open for further replies.

x75

Programmer
Mar 8, 2002
10
DE
Hi,
I have a DataSet,
and would like to step trough all the rows in one of the tables and delete them if an If clause returens true.

I tried:
For Each row In getFreeZimmerList.Tables(0).Rows
If getBelegungList(row.Item("ZimmerID").ToString, vonDate, bisDate).Tables(0).Rows.Count > 0 Then
row.Delete()
End If
Next

but It won't work since this changes the index of the dataset an then I can't step trough it anymore.

I also tried it with:
For I = 0 To getFreeZimmerList.Tables(0).Rows.Count - 1
If (getBelegungList(getFreeZimmerList.Tables(0).Rows(I).Item("ZimmerID").ToString, vonDate, bisDate).Tables(0).Rows.Count > 0) Then
getFreeZimmerList.Tables(0).Copy.Rows(I).Delete
End If
Next I

Same Problem.
Messes up the index.

Does anyone have suggestion on how to do this?
I thought of copping the "good" rows in a secound dataset and then override the first one with it.

But can't get that to work.

Thanks for any help
Johannes
 
Should be able to use a nested while loop. In pseudocode, it might look like:

dim i as integer = 0
while i < rowCount
while theCondition and (i < rowCount)
deleteRow
i += 1
end while
i += 1
end while

Yes, it changes the index, but the first loop makes sure you don't overstep your bounds, and the inner loop deletes rows while the condition is true...

but you still check on every iteration of each loop that you haven't gone over the rowCount, which should avoid any error condition.

So rather than using your &quot;if&quot; to check, you use that inner while loop.

lemme know -
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top