AcceptChanges
DataTable.AcceptChanges();
Commits all changes made to the DataTable
since
the last time it was loaded or the last time AcceptChanges( )
was called.
The following example demonstrates how to call the
AcceptChanges( )
method of the
DataTable
and the effect of calling
AcceptChanges( )
on the row state:
// 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.AcceptChanges(); // RowState = Unchanged row.Delete(); // RowState = Deleted dt.AcceptChanges(); // Row is removed from the DataTable
Calling AcceptChanges( )
sets the
RowState
property of Added
and
Modified
rows to Unchanged
; the
original values in the DataRow
are set to the
current values. Deleted
rows are removed from the
DataTable
.
Calling the AcceptChanges( )
method on the
DataTable
causes AcceptChanges
to be called on each DataRow
belonging to the
DataTable
. Calling the AcceptChanges( )
method of a DataSet
that the table
belongs to implicitly calls the AcceptChanges( )
method of the table.
EndEdit( )
is implicitly called on any
DataRow
objects that are in edit mode as a result
of calling the BeginEdit( )
method of the
DataRow
.
Calling AcceptChanges( )
clears all
RowError
information and sets the
HasErrors
property of the row to
false
.