AcceptChanges Method

Overview

The AcceptChanges method accepts changes across the entire data set. Internally, it iterates through all tables and calls AcceptChanges() on each table. Table-level acceptance is important because accepting deleted rows removes them from the table.

AcceptChanges is commonly used after a successful save operation, or after you decide that the current in-memory state should be treated as the new baseline (no pending local changes).

Declaration

/// <summary>
/// Accepts changes
/// </summary>
/// <param name="dataSet">Data set</param>
public static void AcceptChanges(this IDataSet? dataSet)

Namespace and Assembly

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

Behavior

Important Notes

Usage Example

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

// 2. 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. 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";

// Make the row Unchanged, then modify it
employmentTypeDataRow.AcceptChanges();
employmentTypeDataRow["Description"] = "Part Time";

// 4. Table with one row that will be deleted
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";
employeeDataRow.AcceptChanges();
employeeDataRow.Delete();

// 5. Accept changes at data set level
dataSet.AcceptChanges();

// Expected result:
// - Department: one Unchanged row (1, Reception)
// - EmploymentType: one Unchanged row (1, ET01, Part Time)
// - Employee: deleted row removed from the table

 

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.