AcceptChanges Method

Overview

The AcceptChanges method accepts the row current values as the new baseline and sets the row’s state to Unchanged (when applicable). The baseline is later used by RejectChanges to restore values when changes are rejected.

If the current state of the row is Detached or Unchanged, the AcceptChanges method does nothing.

If the current state of the row is Deleted then AcceptChanges method throws an exception because accepting changes means the deleted row must be removed from the table it belongs to, but that action can be done at table level only.

If the current state of the row is Added or Modified then the AcceptChanges method changes the row's state to Unchanged. For Added and Modified rows, AcceptChanges() discards any stored original-value snapshot and makes current values the baseline.

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 the AcceptChanges method to set row state into Unchanged
departmentDataRow.AcceptChanges();

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 row state into Unchanged
departmentDataRow.AcceptChanges();

// 5. Call DeleteRow method to put row into Deleted state
departmentDataTable.DeleteRow(departmentDataRow);

// 6. Call AcceptChanges method and observe that exception is thrown
departmentDataRow.AcceptChanges();

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 another value to data row field to put row into Modified state
departmentDataRow["Name"] = "Reception";

// 6. Call the AcceptChanges method to accept current values as the new baseline
departmentDataRow.AcceptChanges();

 

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.