Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Accessing Data
 How to: Commit Changes in a Dataset

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Data Access in Client and Middle-Tier Programming 
How to: Commit Changes in a Dataset 

As you make changes to records in a dataset by updating, inserting, and deleting records, the dataset maintains original and current versions of the records. In addition, each row's RowState property keeps track of whether the records are in their original state or have been updated, inserted, or deleted. This information is useful when you need to find a particular version of a row. Typically, you would get a subset of all changed records to send to another process. For more information, see How to: Retrieve Changed Rows. After you have processed all the changed rows, you can commit the changes by calling the AcceptChanges method of the DataSet, DataTable, or DataRow. The AcceptChanges method is called automatically when calling the update methods of a TableAdapter or data adapter. Call AcceptChanges after submitting changes to a database.

When you call AcceptChanges on the DataSet, any DataRow objects still in edit mode successfully end their edits. The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.

If the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

To commit changes in a dataset

  • Call the AcceptChanges method on either a DataSet, DataTable, or DataRow to commit the changes in those objects.

    The following example shows how to call the AcceptChanges method to commit changes in the Customers table after updating a data source:

    Visual Basic
    NorthwindDataSet1.Customers.AcceptChanges()
    
    C#
    northwindDataSet1.Customers.AcceptChanges();
    
    J#
    northwindDataSet1.get_Customers().AcceptChanges();
    

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker