I don\'t understand why this code does not work.
foreach (DataRow dataRow in dataTable.Rows)
{
if (true)
{
dataRow.Delete();
}
}
<
This is because it looks like try to disassemble the stair of staircase that you climb. Simply, you cannot remove an item you iterate.
Therefore you should use different array to iterate and remove them from datatable Rows property.
foreach (DataRow dataRow in dataTable.Select())
{
if (true)
{
dataTable.Rows.Remove(dataRow);
}
}