RejectChanges Method

Overview

The RejectChanges method rejects all pending changes in a table and reverts the table to the last accepted state. It is the table-level counterpart of IDataRow.RejectChanges().

This method uses state-aware logic: it removes newly added (or detached) rows from the table, and it reverts deleted or modified rows back to their original values and state.

Declaration

/// <summary>
/// Rejects changes
/// </summary>
/// <param name="dataTable">Data table</param>
public static void RejectChanges(this IDataTable? dataTable)

Namespace and Assembly

Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll

Behavior

Usage Example

// 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. Reject changes at table level
// - employeeDataRow1 is removed from the table because it was Added
// - employeeDataRow2 remains in the table and becomes Unchanged
// - employeeDataRow3 remains in the table and becomes Unchanged
employeeTable.RejectChanges();

Notes

 

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.