Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Accepting or Rejecting Changes to Rows 

After verifying the accuracy of changes made to data in a DataTable, you can accept the changes using the AcceptChanges method of the DataRow, DataTable, or DataSet, which will set the Current row values to be the Original values and will set the RowState property to Unchanged. Accepting or rejecting changes clears out any RowError information and sets the HasErrors property to false. Accepting or rejecting changes can also affect updating data in the data source. For more information, see Updating Data Sources with DataAdapters.

If foreign key constraints exist on the DataTable, changes accepted or rejected using AcceptChanges and RejectChanges are propagated to child rows of the DataRow according to the ForeignKeyConstraint.AcceptRejectRule. For more information, see Adding Constraints to a Table.

The following example checks for rows with errors, resolves the errors where applicable, and rejects the rows where the error cannot be resolved. Note that, for resolved errors, the RowError value is reset to an empty string, causing the HasErrors property to be set to false. When all the rows with errors have been resolved or rejected, AcceptChanges is called to accept all changes for the entire DataTable.

if (workTable.HasErrors)

  foreach (DataRow errRow in workTable.GetErrors())
    if (errRow.RowError == "Total cannot exceed 1000.")
      errRow["Total"] = 1000;
      errRow.RowError = "";    // Clear the error.


See Also

Community Additions

© 2015 Microsoft