Home > Article > Backend Development > C# DataSet.AcceptChanges method
DataSet.AcceptChanges Method:
Commit all changes made to this DataSet since it was loaded or since AcceptChanges was last called.
Both the DataRow and DataTable classes have AcceptChanges method. Calling AcceptChanges at the DataTable level calls the AcceptChanges method for each DataRow that is called. Likewise, calling AcceptChanges on a DataSet causes AcceptChanges to be called on every table in the DataSet. As such, you can call the method on multiple levels. Calling the DataSet's AcceptChanges will allow you to call the method once for all secondary objects (such as tables and rows).
When AcceptChanges is called on a DataSet, any DataRow object still in editing mode will successfully end its editing. The RowState property of each DataRow is also changed; Added and Modified rows become Unchanged, and Deleted rows are removed.
If the DataSet contains a ForeignKeyConstraint object, calling the AcceptChanges method will also cause the AcceptRejectRule to be enforced.
The code is as follows (assembly: System.Data (in system.data.dll)):
public void AcceptChanges() { IntPtr intPtr; Bid.ScopeEnter(out intPtr, "<ds.DataRow.AcceptChanges|API> %d#\n", this.ObjectID); try { this.EndEdit(); if (this.RowState != DataRowState.Detached && this.RowState != DataRowState.Deleted && this._columns.ColumnsImplementingIChangeTrackingCount > 0) { DataColumn[] columnsImplementingIChangeTracking = this._columns.ColumnsImplementingIChangeTracking; for (int i = 0; i < columnsImplementingIChangeTracking.Length; i++) { DataColumn column = columnsImplementingIChangeTracking[i]; object obj = this[column]; if (DBNull.Value != obj) { IChangeTracking changeTracking = (IChangeTracking)obj; if (changeTracking.IsChanged) { changeTracking.AcceptChanges(); } } } } this._table.CommitRow(this); } finally { Bid.ScopeLeave(ref intPtr); } }
The above is the C# DataSet.AcceptChanges method Content, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!