AcceptChanges
DataRow.AcceptChanges();
Commits all changes made to the DataRow
since the
last time it was loaded or since the last time
AcceptChanges( )
was called.
The following example demonstrates how to call the
AcceptChanges( )
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.AcceptChanges(); // RowState = Unchanged row.Delete(); // RowState = Deleted row.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 as the
current values. Deleted
rows are removed from the
DataTable
.
Calling the AcceptChanges( )
method of the table
the row belongs to implicitly calls the AcceptChanges( )
method of the row.
If the DataRow
is in edit mode, as a result of
calling the BeginEdit( )
method, EndEdit( )
is implicitly called, ending the edit.
Calling AcceptChanges( )
clears all
RowError
information and sets the
HasErrors
property for the row to
false
.