RemoveAt, Remove, delete usage differences in C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.