RejectChanges
DataTable.RejectChanges();
Rejects all changes made to the DataTable
since
the last time it was loaded or since the last time
AcceptChanges( )
was called.
The following example demonstrates how to call the
RejectChanges( )
method of the
DataTable
:
// create a table with a single column DataTable dt = new DataTable(); dt.Columns.Add("MyColumn", typeof(System.Int32)); DataRow row; row = dt.NewRow(); row["MyColumn"] = 1; dt.Rows.Add(row); // RowState = Added dt.AcceptChanges(); // RowState = Unchanged row["MyColumn"] = 2; // RowState = Modified dt.RejectChanges(); // RowState = Unchanged, row["MyColumn"] = 1 row.Delete(); // RowState = Deleted dt.RejectChanges(); // RowState = Unchanged // The row isn't removed from the DataTable.
Calling RejectChanges( )
sets the
RowState
property of Deleted
and Modified
rows to Unchanged
;
the current values in the DataRow
are set to the
original values. Added
rows are removed.
Calling the RejectChanges( )
method on the
DataTable
causes RejectChanges( )
to be called on each DataRow
belonging
to the DataTable
. Calling the
RejectChanges( )
method of the
DataSet
that the table belongs to implicitly calls
the RejectChanges( )
method of the table.
Any DataRows
in edit mode as a result of calling
BeginEdit( )
cancel their edits when
RejectChanges( )
is called.
Calling RejectChanges( )
clears all
RowError
information and sets the
HasErrors
property to false
.