Committing and Discarding Changes

When a DataRow is modified, ADO.NET marks the row as having a pending change and sets the RowState of the DataRow to Added, Modified, or Deleted as appropriate. ADO.NET also maintains version information by tracking both Original and Current versions of each row. Together, this information allows ADO.NET to identify the rows and columns that have been changed.

The DataTable has three methods—GetChanges( ) , AcceptChanges( ), and RejectChanges( )—that can commit or discard the changes made to a DataTable since it was last loaded or since AcceptChanges( ) was last called. These methods function identically to the same methods for the DataSet as they are described in Chapter 6. Also, when these methods are called on a DataSet, they are implicitly called on all tables contained within the DataSet.

Get ADO.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.