C# - DataTable.AcceptChanges() in a data table
About DataTable.AcceptChanges Method (System.Data)
The DataTable’s AcceptChanges() method commits the changed done to the DataRow and the DataTable’s RejectChanges() method rolls back the changes done to the DataRow.
DataRow
drEmp;
// Add a
new Row and perform data changes
drEmp = dtEmployee.NewRow(); // RowState -
Detached
dtEmployee.Rows.Add(drEmp); // RowState -
Added
dtEmployee.AcceptChanges(); // RowState -
Unchanged
drEmp["ID"]
= 2312; // RowState - Modified
dtEmployee.AcceptChanges(); // RowState -
Unchanged
drEmp.Delete(); //
RowState - Deleted
dtEmployee.AcceptChanges(); // RowState -
Detached
gvEmployees.DataSource =
dtEmployee;
RowState before
calling AcceptChanges()
|
RowState after
calling AcceptChanges()
|
Impact on the
Row
|
Added
|
Unchanged
|
New row is
commited to the DataTable
|
Modified
|
Unchanged
|
Data Changes to
the row are committed to the DataTable
|
Deleted
|
Detached
|
Row is
Permanently Removed from the DataTable
|
Referenced by http://msdn.microsoft.com/en-IN/library/system.data.datatable.acceptchanges.aspx
C# - DataTable.AcceptChanges() in a data table
Reviewed by Ravi Kumar
on
10:51 PM
Rating:
No comments: