DeleteRow Method

Overview

The DeleteRow method deletes a row from an IDataTable using state-aware semantics. It supports both "undo creation" for newly added rows and "soft delete" for existing rows that should be preserved for save/merge operations.

This method is a table-level helper. It verifies that the row belongs to the table and then applies a deletion strategy based on IDataRow.DataRowState.

Declaration

/// <summary>
/// Deletes row from table
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="dataRow"<Data row</param<
public static void DeleteRow(this IDataTable? dataTable, IDataRow? dataRow)

Namespace and Assembly

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

Behavior

Usage Example

// 1. Create an empty data set and a table
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeDataTable.AddColumn("LastName", DataTypeNames.STRING);

// 2. Add a row in Added state
IDataRow employeeDataRow1 = employeeDataTable.AddNewRow();
employeeDataRow1["Id"] = 1;
employeeDataRow1["FirstName"] = "John";
employeeDataRow1["LastName"] = "Doe";

// 3. Add a row in Unchanged state
IDataRow employeeDataRow2 = employeeDataTable.AddNewRow();
employeeDataRow2["Id"] = 2;
employeeDataRow2["FirstName"] = "Sara";
employeeDataRow2["LastName"] = "Gor";
employeeDataRow2.AcceptChanges();

// 3. Add a row in Modified state
IDataRow employeeDataRow3 = employeeDataTable.AddNewRow();
employeeDataRow3["Id"] = 1;
employeeDataRow3["FirstName"] = "Paul";
employeeDataRow3["LastName"] = "Carry";
employeeDataRow3.AcceptChanges();
employeeDataRow3["FirstName"] = "Tom";

// Call DeleteRow method on each row
// Added row removed from table
employeeDataTable.DeleteRow(employeeDataRow1);

// Unchanged row marked as deleted
employeeDataTable.DeleteRow(employeeDataRow2);

// Modified row marked as deleted
employeeDataTable.DeleteRow(employeeDataRow3);

 

Table of Content POCO DataSet DataTable Extensions Group DataTable 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.