Clone Method

Overview

The Clone method creates a new data table instance and copies the schema and rows from an existing table. Internally, it:

The returned table is independent from the source table (a separate instance), but it contains the same schema and data.

Declaration

/// <summary>
/// Clones data table
/// </summary>
/// <param name="dataTable">Data table</param>
/// <returns>Cloned data table</returns>
public static IDataTable? Clone(this IDataTable? dataTable)

Namespace and Assembly

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

Behavior

Usage Example

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

// 2. Create an empty Department table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Add several rows to the Department table
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Id"] = 1;
departmentDataRow["Name"] = "Customer Service";

departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Id"] = 2;
departmentDataRow["Name"] = "Financial";

// 4. Clone the table (schema + rows)
IDataTable? clonedDepartmentDataTable = departmentDataTable.Clone();

Notes

 

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.