I have a table in a dataset. I need to delete several rows in that table. But if I do like this:
For Each row In newDataTable.Rows
If row(1) = 505050 Then
newDataTable.Rows(linenr).Delete()
End If
linenr = linenr + 1
Next
then the line count changes and give me the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
Is there an alternative way of deleting rows in a dataset?
Like the SQL-way; 'DELETE FROM table WHERE ID=505050'
For Each row In newDataTable.Rows
If row(1) = 505050 Then
newDataTable.Rows(linenr).Delete()
End If
linenr = linenr + 1
Next
then the line count changes and give me the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
Is there an alternative way of deleting rows in a dataset?
Like the SQL-way; 'DELETE FROM table WHERE ID=505050'