Tag: Ring count requires DataRow to cancel remove DataTable difference rollback
There are three ways to delete a DataRow in a DataTable:
Delete method and Remove method and RemoveAt method
The difference is:
The Delete method does not actually delete a row from the DataTable, but instead flags it as a delete, just a token,
The Remove method actually deletes a row from the DataRow,
The RemoveAt method is deleted based on the index of the row.
The use of Delete is: datatable.rows[i]. Delete ();
Note: A DataTable is required after Delete (). The Acceptechanges () method confirms a complete deletion because delete () simply flags it as deleted and can be used in a DataTable. RejectChanges () rollback to make the row undelete.
The use of Remove is: Datatable.Rows.Remove (Datatable. Rows[i]);
The use of RemoveAt is: DataTable.Rows.RemoveAt (index);
If the RemoveAt method is removed, if it is the loop to be careful to delete from the back, that is, i--, for example:
for (int i = 0; i < dgv_datalist. Rows.Count; i--)
{//delete "waybill number" ==item. Line with waybill number
Dgv_datalist. Rows[i]. cells["waybill number"]. Value.tostring (). Equals (item. waybill number);
Dgv_datalist. Rows.removeat (i);
}
RemoveAt, Remove, delete usage differences in C #