Clear Method

Overview

The Clear method removes all rows from every table in an IDataSet. It does not remove tables, columns, or other schema metadata.

Use this method when you want to reuse the same data set instance and schema but discard all loaded or edited rows.

Declaration

/// <summary>
/// Clears all rows from all tables in the data set.
/// Keeps schema (tables and columns) intact.
/// </summary>
/// <param name="dataSet">Data set.</param>
public static void Clear(this IDataSet? dataSet)

Namespace and Assembly

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

Behavior

Usage Example

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

// 2. Create Employee data table and add columns
IDataTable employeeTable = dataSet.AddNewTable("Employee");
employeeTable.AddColumn("Id", DataTypeNames.INT32);
employeeTable.AddColumn("FirstName", DataTypeNames.STRING);

// 3. Add a new row
IDataRow dataRow = employeeTable.AddNewRow();
dataRow["Id"] = 1;
dataRow["FirstName"] = "Sara";

// 4. Clear all rows from all tables (keeps schema)
dataSet.Clear();

// 5. Verify that Employee table has no rows but still has columns
bool noRows = employeeTable.Rows.Count == 0;
bool hasTwoColumns = employeeTable.Columns.Count == 2;

 

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.