RejectChanges
DataRow.RejectChanges();
Rejects all changes made to the DataRow
since the
last time it was loaded or since the last time
AcceptChanges( )
was called.
This example demonstrates how to call the RejectChanges( )
method of the DataRow
:
// 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 row.AcceptChanges(); // RowState = Unchanged row["MyColumn"] = 2; // RowState = Modified row.RejectChanges(); // RowState = Unchanged, row["MyColumn"] = 1 row.Delete(); // RowState = Deleted row.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.
If the row is in edit mode as a result of calling BeginEdit( )
, the edit is cancelled when RejectChanges( )
is called.
Calling RejectChanges( )
clears all
RowError
information and sets the
HasErrors
property to false
.