I faced a problem with a DataTable. When I run to client it throws an Exception and mentions the "in" in foreach.
Collection was modified; enumeration operation might not execute.
This is the code:
foreach (DataRow dr in stStatusTable.Rows)
{
if (Convert.ToInt32(dr["st_id"]) == stStatus.st_id)
{
dr["st_id"] = Convert.ToInt32(dr["st_id"]) + 1;
dr.AcceptChanges();
}
else
{
stStatusTable.Rows.Add(stStatus.st_id, stStatus.st_name, stStatus.RTime, stStatus.Total_Mark, stStatus.Completed);
}
}
How can I solve this?