RejectChanges Method

Overview

The RejectChanges method reverts a row to its baseline (original) values captured by the framework. The method behaves differently depending on the current state of the row.

If the current state of the row is Detached or Unchanged then RejectChanges method does nothing.

If the current state of the row is Added, the RejectChanges method throws an exception because "reject changes" means added row needs to be removed from the table it was added to, but that action must be performed at table level (for example, IDataTable.RejectChanges).

If the current state of the row is Deleted or Modified then the RejectChanges method restores row values from the snapshot if it exists and changes the row's state to Unchanged. If no snapshot exists, it still sets state to Unchanged and clears snapshot (which is already null).

Important notes:

Namespace and Assembly

Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll

Usage Example

Row in the "Added" state:

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create an empty data table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Create a new row by AddNewRow method on data table, the row state is Added
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Name"] = "Emergency";

// 4. Call RejectChanges method and observe thrown InvalidOperationException
departmentDataRow.RejectChanges();

Row in the "Deleted" state:

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create an empty data table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Create a new row by AddNewRow method on data table, the row state is Added
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Name"] = "Emergency";

// 4. Call the AcceptChanges method to set the baseline based on the entered values. Row state is Unchanged
departmentDataRow.AcceptChanges();

// 5. Call the Delete method to set the row into Deleted state.
departmentDataRow.Delete();

// 6. Call RejectChanges method and observe that row state is back to Unchanged
departmentDataRow.RejectChanges();

Row in the "Modified" state:

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create an empty data table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Create a new row by AddNewRow method on data table, the row state is Added
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Name"] = "Emergency";

// 4. Call the AcceptChanges method to set row state into Unchanged
departmentDataRow.AcceptChanges();

// 5. Assign a new value to put row into Modified state
// At this moment the baseline snapshot is created to keep Name="Emergency" for RejectChanges action
departmentDataRow["Name"] = "Reception";

// 6. The subsequent assignments do not change once captured baseline
departmentDataRow["Name"] = "HR";

// 7. Call RejectChanges method and observe that row state is back to Unchanged, "Name" is back to "Emergency", and baseline is deleted
departmentDataRow.RejectChanges();

 

Table of Content POCO DataSet API References POCO DataSet Types DataRow 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.