I would say that you should make a separate table of records, and instead of calling datatable.Rows.Remove (rows) add the row "rows" to this other table. Then, when the lines or lines of iteration are executed, you run the if statement to check if it has been "deleted", i.e. In the list of deleted rows. After the listing ends, you can delete these rows from the table.
EDIT:
Here's the code implementation:
DataTable duplicates = dataTable; duplicates.Rows.Clear(); foreach (DataRow row in dataTable.Rows) { if (!duplicates.Rows.Contains(row)) { temp = row[0].ToString(); foreach (DataRow rows in dataTable.Rows) { if (temp == rows[0].ToString()&&!duplicates.Rows.Contains(rows))
if you donβt have a unique key, you can try switching !duplicates.Rows.Contains(/*specific row*/) to duplicates.Rows.IndexOf(/*specific row*/)>0 . This should provide an adequate replacement.
source share