I know Bonnie answered this question, but even I can spot an error in your code. The same applies to VFP also.
You can not use FOR EACH loop and remove a member of collection at the same time. It should be even documented in the FOR EACH loop (in C# I do remember reading it).
If you need to remove a member of collection, then you need to use next loop and start from the last member and do it backwards.
>>What code are you using that you get this error? A DataRow can call it's Delete() method with no problem. Are you doing something peculiar?
>
>I always have to do something like this:
>
>
> loDataView = New DataView(loDataProvider.oDataSet.Tables.Item(0))
>
> loDataView.RowFilter = "Flag=1"
>
> ' Delete all records which have been flagged
> For Each loRowView In loDataView
> loRowView.Delete()
> Next
>
> loDataView.RowFilter = ""
> loDataView.Table.AcceptChanges()
>
> ' Adjust the count
> loDataProvider.nCount = loDataProvider.oDataSet.Tables("Temp").Rows.Count
>
>
>Because, if I scan my dataset, and based on a condition, I want to remove the record, it will tell me that the Delete() method cannot be used:
>
>
> ' For each message
> For lnCounter = 0 To loDataProvider.nCount - 1
> loRow = loDataProvider.oDataSet.Tables("Temp").Rows(lnCounter)
>
> ' If we have to delete the row
> If True Then
> loRow.Delete()
> End If
>
> Next
>
If it's not broken, fix it until it is.
My Blog