>Hi,
>I would like to loop thru datatable.rows and check for any empty row (certain fields are empty). If any, rejectchange.
>
>I try the following code, it complaint "collection was modified". Any other wy to do this?
>
>
foreach(DataRow loRow in DataTable.Rows)
>{
> if (loRow["MyField"] = string.Empty)
> {
> loRow.RejectChanges();
> }
>}
>
>Please advice.
>
>Thank you
You can't modify a collection with an iterator like foreach. However you could instead use for() in reverse to do that.
for(i=myTable.Rows.Count-1;i>=0;i--)
{
if ((string)myTable.Rows[i]["MyField"] == String.Empty)
{
myTable.Rows[i].RejectChanges();
}
}
Cetin