I have a data table and I want to delete a row here is my code it's throwing me an exception
foreach (DataRow row in dt1.Rows)
{
if ((row["Name"] == "Select a Lookbook") || (row["Name"] == "Create a new Lookbook"))
{
row.Delete();
dt1.AcceptChanges();
}
}
I even tried outside the if statment and outside forloop still throws me error any idea how to achieve this task this is the exception I get:
Collection was modified; enumeration operation might not execute.
Final working Code:
foreach (DataRow row in dt1.Select())
{
if ((row["Name"] == "Select a Lookbook") || (row["Name"] == "Create a new Lookbook"))
{ row.Delete();
}
}