The reason is as follows:
After the Delete () operation, you must use the able. AccepteChanges () method to confirm that the data is completely deleted, because Delete () only marks the status of the corresponding column as deleted,
You can also use datatable. RejectChanges () to roll back the row to cancel deletion.
To completely Delete datarow, you must use the Delete () and AccepteChanges () methods at the same time, or use the able. Rows. RemoveAt (I) method to directly Delete the datarow,
Where I indicates the row index, and datatable. Rows. Remove (DataRow dr) deletes the specified row.
However, when using datatable. Rows. RemoveAt (I), note that if you use able. Rows. RemoveAt (0); datatable. Rows. RemoveAt (1 );
In this case, the rows 0 and 1 in the original table are not deleted, but after the rows 0 are deleted, the original Row 1 becomes 0, so the datatable. rows. removeAt (1) actually deletes two rows of the original table.
Therefore, you should use datatable. Rows. RemoveAt (I) with caution. To Delete multiple Rows, you can use Delete () consecutively and then use the AccepteChanges () method to confirm the deletion.
Solution example:
Copy codeThe Code is as follows: List <string> lst = new List <string> ();
For (int I = 0; I <_ Table. Rows. Count; I ++)
{
If (_ Table. Rows [I]. RowState! = DataRowState. Deleted)
{
Lst. Add (_ Table. Rows [I] ["I _SL"]. ToString () = "0 "? "False": "true ");
}
}