CloneRowsFrom Method
The CloneRowsFrom method clones all rows from a source table into a destination (cloned) table.
It creates a new IDataRow instance for each source row and adds it to the destination table.
This method is intended to be used after the destination table schema (columns) has already been cloned
(for example, by calling CloneColumnsFrom). It does not clone column metadata by itself.
/// <summary>
/// Clones rows from data table
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="sourceDataTable">Source data table</param>
public static void CloneRowsFrom(this IDataTable? dataTable, IDataTable? sourceDataTable)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
clonedDataTable is null or dataTable is null, returns immediately.dataTable.Rows and for each row:
clonedDataTable via AddRow.When copying values from the source row to the target row, the method attempts to clone values using simple rules:
Null: copied as null.int, long, decimal, DateTime, bool, etc.): copied by value.String: copied as-is (strings are immutable).byte[]: cloned into a new array to avoid sharing the same buffer.ICloneable: cloned by calling Clone().
The following example shows how to clone schema and rows from the Department table into a new table:
// 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 rows to the Department table
IDataRow departmentDataRow1 = departmentDataTable.AddNewRow();
departmentDataRow1["Id"] = 1;
departmentDataRow1["Name"] = "Customer Service";
IDataRow departmentDataRow2 = departmentDataTable.AddNewRow();
departmentDataRow2["Id"] = 2;
departmentDataRow2["Name"] = "Finance";
// 4. Create an empty table and add schema to it
IDataTable clonedDepartmentDataTable = new DataTable();
clonedDepartmentDataTable.TableName = departmentDataTable.TableName;
clonedDepartmentDataTable.CloneColumnsFrom(departmentDataTable);
// 5. Clone rows
clonedDepartmentDataTable.CloneRowsFrom(departmentDataTable);
AddRow,
and the resulting row state is determined by the destination table and row implementation.
byte[] and arrays), but they do not guarantee
a deep clone for arbitrary object graphs.
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.