RejectChanges Method
The RejectChanges method rejects changes across the entire data set.
Internally, it iterates through all tables in the data set and calls RejectChanges() on each table.
Rejecting changes reverts the in-memory state back to the baseline values that were established by the last
successful AcceptChanges call. It is typically used when the user cancels an edit operation and the
application wants to discard all pending local changes.
/// <summary>
/// Reject changes
/// </summary>
/// <param name="dataSet">Data set</param>
public static void RejectChanges(this IDataSet? dataSet)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataSet is null, returns immediately.dataSet.Tables and calls RejectChanges() on each table.
RejectChanges() is responsible for the row-level rules
(for example, removing Added rows, undeleting Deleted rows, restoring original values for Modified rows).
RejectChanges is not a validation step. Validation should happen at application layers.
RejectChanges is a local operation; it does not communicate with a database.
// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Create data table with one row in Added state
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Id"] = 1;
departmentDataRow["Name"] = "Reception";
// 3. Create data table with one row in Modified state
IDataTable employmentTypeDataTable = dataSet.AddNewTable("EmploymentType");
employmentTypeDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeDataTable.AddColumn("Code", DataTypeNames.STRING);
employmentTypeDataTable.AddColumn("Description", DataTypeNames.STRING);
IDataRow employmentTypeDataRow = employmentTypeDataTable.AddNewRow();
employmentTypeDataRow["Id"] = 1;
employmentTypeDataRow["Code"] = "ET01";
employmentTypeDataRow["Description"] = "Full Time";
employmentTypeDataRow.AcceptChanges();
employmentTypeDataRow["Description"] = "Part Time";
// 4. Create data table with one Deleted row
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeDataTable.AddColumn("LastName", DataTypeNames.STRING);
IDataRow employeeDataRow = employeeDataTable.AddNewRow();
employeeDataRow["Id"] = 1;
employeeDataRow["FirstName"] = "John";
employeeDataRow["LastName"] = "Doe";
employeeDataTable.AcceptChanges();
employeeDataRow.Delete();
// 5. Reject changes at data set level
dataSet.RejectChanges();
// Expected result:
// - Department table without rows (Added row removed)
// - EmploymentType row restored to Unchanged: 1, ET01, Full Time
// - Employee row restored to Unchanged: 1, John, Doe
Table of Content POCO DataSet DataSet 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.