When I use the following code, I'm getting a "Collection was modified; enumeration operation might not execute" error. If I understand this correctly, I think it means that I can't enumerate over this datatable and delete rows from it at the same time. My question is, what else can I do to achieve the result of deleting certain rows from my datatable? Here's my code:
// Now let's loop through the datatable and find any account with no
// LYSMKWh value and less than 4000 KWh current usage. We'll remove those
// from the datatable.
currentRow = 0;
foreach (DataRow row in resultsDT.Rows)
{
if ((string)resultsDT.Rows[currentRow]["LYSMKWh"] == "0")
{
int intKWh = Convert.ToInt32(resultsDT.Rows[currentRow]["KWH"]);
if (intKWh < 5000)
{
resultsDT.Rows[currentRow].Delete();
}
}
resultsDT.AcceptChanges();
currentRow++;
}