Commits all the changes made to this table since the last time AcceptChanges was called.
[Visual Basic] Public Sub AcceptChanges() [C#] public void AcceptChanges(); [C++] public: void AcceptChanges(); [JScript] public function AcceptChanges();
When AcceptChanges is called, any DataRow object still in edit-mode successfully ends its edits. The DataRowState also changes: all New and Modified rows become Unchanged; Deleted rows are removed.
CAUTION The AcceptChanges method should never be called on a DataTable until after you attempt to update the DataSet using the TBD method. When you invoke AcceptChanges, all rows marked as New, Modified, or Deleted will then become marked Original. In that case, the DataSet has no way of knowing which rows must be propagated to the database management system.
The following example edits the value of one column in the last row of a System.WinForms.DataGrid control. The example uses the BeginEdit, EndEdit, and AcceptChanges methods to programmatically edit the column's value and commit the change to the row, and finally to the table itself.
[Visual Basic]
Private Sub EditAndAccept() Dim t As DataTable t = DataGrid1.DataSource Dim myRow As DataRow myRow = t.Rows(t.Rows.Count - 1) myrow.BeginEdit myrow(1) = "New Text" myrow.EndEdit myrow.AcceptChanges t.AcceptChanges End Sub
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | BeginEdit | DataRowState | EndEdit | RejectChanges