Delete and remove methods for DataTable deletion rows

Source: Internet
Author: User

2 . Only after the Datatable.remove (DataRow) method is called, the DataRow is removed from the DataTable and the state is returned to the detached orphaned state, and the subsequent database does not change.

There are two ways to remove a DataRow object from a DataTable object: The Remove method of the DataRowCollection object and the Delete method of the DataRow object. The Remove method removes a DataRow from DataRowCollection, and the Delete method only marks the row for deletion. The actual deletion occurs only when the application calls the AcceptChanges method. By using Delete, you can programmatically check which rows are marked for deletion before you actually delete them. If the row is marked for deletion, its RowState property is set to Deleted.

So: When using a DataSet or DataTable with DataAdapter and relational data sources, remove rows with the Delete method of the DataRow.      The Delete method simply marks the row as Deleted in the DataSet or DataTable and does not remove it.      DataAdapter, when encountering a row marked Deleted, executes its DeleteCommand method to delete the row in the data source. You can then permanently remove the row by using the AcceptChanges method.

If you use Remove to delete the row, it is completely removed from the table, but DataAdapter does not delete the row in the data source.

--------------------Transfer from: http://www.cnblogs.com/lionwang/p/4433311.html

Delete and remove methods for DataTable deletion rows

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.