AcceptChanges Method
The AcceptChanges method accepts changes for all rows in a table.
It is the table-level equivalent of committing the current in-memory state as the new baseline.
A key difference compared to row-level acceptance is how deletions are handled:
when a row is in Deleted state, accepting that deletion removes the row from the table.
For this reason, this method iterates rows from the end to the beginning and removes deleted rows
safely by index.
/// <summary>
/// Accepts changes
/// If a caller calls AcceptChanges() on unsaved changes that include Deleted rows then Deleted rows will be removed from table.
/// The caller must understand and accept the consequences.
/// </summary>
/// <param name="dataTable">Data table</param>
public static void AcceptChanges(this IDataTable? dataTable)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns immediately.Rows.Count - 1 down to 0.
This backward iteration is required because accepting a deletion removes the row from the table.
Deleted: the method commits the deletion by removing the row from the table
via RemoveRowAt(index).
Added and Modified: the method calls IDataRow.AcceptChanges(),
which typically transitions the row to Unchanged.
Unchanged and Detached: no action is taken.
AcceptChanges while there are unsaved deleted rows, those rows will be permanently removed
from the table (in-memory). The caller must understand and accept this consequence.
// 1. Create an empty data set and a table
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable employeeTable = dataSet.AddNewTable("Employee");
employeeTable.AddColumn("Id", DataTypeNames.INT32);
employeeTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeTable.AddColumn("LastName", DataTypeNames.STRING);
// 2. Add a row (Added state)
IDataRow employeeDataRow1 = employeeTable.AddNewRow();
employeeDataRow1["Id"] = 1;
employeeDataRow1["FirstName"] = "John";
employeeDataRow1["LastName"] = "Doe";
// 3. Add a row and then delete it (Deleted state)
IDataRow employeeDataRow2 = employeeTable.AddNewRow();
employeeDataRow2["Id"] = 2;
employeeDataRow2["FirstName"] = "Sara";
employeeDataRow2["LastName"] = "Gor";
employeeDataRow2.AcceptChanges();
employeeDataRow2.Delete();
// 3. Add a row and modify its value (Modified state)
IDataRow employeeDataRow3 = employeeTable.AddNewRow();
employeeDataRow3["Id"] = 1;
employeeDataRow3["FirstName"] = "Paul";
employeeDataRow3["LastName"] = "Carry";
employeeDataRow3.AcceptChanges();
employeeDataRow3["FirstName"] = "Tom";
// 4. Accept changes at table level
// - employeeDataRow1 remains in the table and becomes Unchanged
// - employeeDataRow2 is removed from the table because it was Deleted
// - employeeDataRow3 remains in the table and becomes Unchanged
employeeTable.AcceptChanges();
Table of Content POCO DataSet DataTable Extensions Group DataTable Members
Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the
Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate
credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness
or suitability of the information and are not responsible for any damages
resulting from its use.