Nguyen,
It's not allowed to change the iteration variable of a for each loop.
In this case 'dtRow'!
When you call dt.Row.Delete() you attempt to change this variable...
You can easily verify this beheaviour by typing this into your compiler:
(you can change it to VB...)
int[] intArray = {1, 2, 3, 4}; //Array of integers
foreach(int i in intArray)
{
i = 5;
}
The above code will not compile!!
I hope this helps...
Peter
"Nguyen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Do you know what's wrong with the code below? I get an error: error in
> method ~MoveNext: collection was modified. Enumeration operation may not
> execute. It happens when I step through the 'Next' of for-loop
>
> Thanks in advance,
>
> V.
>
> -----------------------------------
>
> Dim dtRow As DataRow
>
> With ds.Tables(0)
>
> For Each dtRow In .Rows
>
> If dtRow.IsNull("POPLINE") Then
>
> dtRow.Delete()
>
> End If
>
> Next
>
> End With
>
>
>
|