Partilhar via


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:

    NorthwindDataSet1.Customers.AcceptChanges()
    
    northwindDataSet1.Customers.AcceptChanges();
    

See Also

Tasks

How to: Retrieve Changed Rows

Reference

DataSet.AcceptChanges

DataTable.AcceptChanges

DataRow.AcceptChanges

Concepts

Saving Data