<分区>
当我使用以下代码时,出现“集合已修改;枚举操作可能无法执行”错误。如果我理解正确,我认为这意味着我无法枚举此数据表并同时从中删除行。我的问题是,我还能做些什么来实现从我的数据表中删除某些行的结果? 这是我的代码:
// 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++;
}