What is the use of the Datatable.acceptchanges method

Source: Internet
Author: User

Commits all changes made to the table since the last call to AcceptChanges.

After calling AcceptChanges, the DataAdapter.Update () will not have any new data to be updated into the database . That...... What's the use of it?

Past Practice:

Fill–> edit–>update–> again fill–> edit–> update–> ...

"Update the data, of course, to get it again!" ", once again updated, get again again.

Today's approach:

fill–> edit–> update–> acceptchanges–> edit–> update–> acceptchanges–> edit–> update–> ......

Start to get one at a time, anyway, after you update the data and then get what you just updated, why do you want to get it again?

AcceptChanges after the Update!

-----------------------------------------Ugly Cutting Line-------------------------------------------------------------

AcceptChanges () and RejectChanges () http://www.cnblogs.com/perfect/archive/2007/08/06/844634.html

Recently in the garden read a few related articles, summed up (also please correct me):
Delete () is an object-oriented state operation (capable of rolling back); RemoveAt () is for normal set operations (cannot be rolled back, equivalent to delete () after AcceptChanges ())

The

Datatable.acceptchanges method
Commits all changes made to the table since the last call to AcceptChanges. When you call AcceptChanges, the DataRow object, regardless of what is still in edit mode, will successfully end its edits. DataRowState will also change: the state of the rows with all States Added and Modified is changed to unchanged, and the rows with Deleted status are removed.
After you try to update the DataSet using the Dbdataadapter.update method, the AcceptChanges method is typically called on the DataTable. The Datatable.rejectchanges method
rolls back all changes made to the table since the table was loaded or last called AcceptChanges. When the
calls RejectChanges, any DataRow object that is still in edit mode cancels its edits. A new row is removed. DataRowState the rows that are set to Modified or Deleted return to their initial state. After you use the Delete method, RowState becomes "deleted." It remains "deleted" until you call AcceptChanges. You can cancel the deletion of a row by calling RejectChanges. RemoveAt indicates that all data in the row will be lost when the row is removed. You can also call the Delete method of the DataRow class to mark a row for removal. Calling RemoveAt is equivalent to calling Delete before calling AcceptChanges. That is, using the Delete () method to delete a row is capable of rolling back, and using the RemoveAt (int) method cannot be rolled back. Summary:
1, delete () after receiving AcceptChanges (), all just add the deletion tag, and then accept the AcceptChanges () again after the actual deletion, otherwise did not accept AcceptChanges () Encountered RejectChanges () was able to rollback
2, delete () did not receive AcceptChanges (), then immediately accept AcceptChanges (), and actually delete
3, delete () The AcceptChanges () was not received before, and it was not immediately accepted AcceptChanges () and would be completely removed: because there is no need to rollback the

What is the

Datatable.acceptchanges method useful for

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.