Delete Method
The Delete method marks a row as Deleted
but does not remove it from the table. The Delete method behaves
differently depending on the current state of the specified row.
If the current state of the row is Deleted or Detached then Delete method does nothing.
If the current state of the row is Added, then the Delete method throws an
exception because deleting an added row means it must be removed from the table
it was added to, but that action can be done at table level only.
If the current state of the row is Unchanged or Modified then the Delete
method changes the row's state to Deleted.
When Delete is called on a row in the Unchanged or
Modified state, the framework creates a snapshot of the row’s
original values (if one does not already exist). This snapshot allows the
deletion to be reverted later by calling RejectChanges.
Important notes:
Delete is a logical operation and does not immediately remove the row.RejectChanges.
Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll
Row in the "Unchanged" 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 Delete method to mark row as Deleted but not to remove it from table
departmentDataRow.Delete();
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 Delete method and observe that an InvalidOperationException is thrown
departmentDataRow.Delete();
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
departmentDataRow["Name"] = "Reception";
// 6. Call Delete method to logically delete the row (row remains in the table)
departmentDataRow.Delete();
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.