CloneColumnsFrom Method
The CloneColumnsFrom method clones column metadata from one table into another table.
For every column in the source table, it creates a new ColumnMetadata instance, copies all metadata
properties, and adds the cloned column metadata to the target table.
This method clones schema only (column metadata). It does not clone rows.
To clone both schema and rows, use Clone (which calls CloneColumnsFrom and CloneRowsFrom).
/// <summary>
/// Clones columns from the source data table
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="sourceDataTable">Source data table</param>
public static void CloneColumnsFrom(this IDataTable? dataTable, IDataTable? sourceDataTable)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
clonedDataTable is null or dataTable is null, the method returns immediately.dataTable.Columns and for each IColumnMetadata:
ColumnMetadata instance.ColumnName, DataType, nullability, PK/FK flags, display metadata, and reference metadata.clonedDataTable.Columns.clonedDataTable; it appends cloned columns to the current list.
The following example shows how to clone column metadata from Department 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. Create an empty ClonedDepartment table
IDataTable clonedDepartmentDataTable = new DataTable();
clonedDepartmentDataTable.TableName = departmentDataTable.TableName;
// 4. Clone only the column metadata (schema)
clonedDepartmentDataTable.CloneColumnsFrom(departmentDataTable);
ColumnMetadata instances. The cloned table does not share
IColumnMetadata object references with the source table.
clonedDataTable already contains
columns, you should ensure you are not creating duplicates.
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.