ADO itterate datatable & delete row

  • Thread starter Thread starter Doug Versch
  • Start date Start date
D

Doug Versch

Hi,

I am trying to itterate through a datatable and delete selected rows but I
get an error stating that the collection has changed when the row is
deleted.

Try
For Each drOrds In dsRecPurchs.Tables("PurchaseRecpts").Rows
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try
How do I itterate and Delete or batch Delete for a set criteria?

Thanks Doug
 
Hi,

You cant use a for each loop to delete records. Use a for next
loop

Dim drOrds as datarow
Try
For x as integer = dsRecPurchs.Tables("PurchaseRecpts").Rows.count -1 to 0
step -1
drOrds = dsRecPurchs.Tables("PurchaseRecpts").Rows(x)
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try

Ken
---------------------
Hi,

I am trying to itterate through a datatable and delete selected rows but I
get an error stating that the collection has changed when the row is
deleted.

Try
For Each drOrds In dsRecPurchs.Tables("PurchaseRecpts").Rows
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try
How do I itterate and Delete or batch Delete for a set criteria?

Thanks Doug
 
Back
Top