CopyFrom Method

Overview

The CopyFrom method copies values from a source IDataRow into a current IDataRow using an explicit list of column metadata. Only columns defined in the metadata list are considered.

This method is commonly used during dataset merge, refresh, or synchronization operations, where column-level control is required and not all columns are guaranteed to exist in both source and current rows.

If the source row does not contain a value for a column defined in the metadata list, that column is skipped. If the current row does not contain the column but the source row does, the column is added to the current row, enabling schema evolution.

Declaration

/// <summary>
/// Copies column values from the source data row into the current data row using list of column metadata.
/// If the source data row does not contain a field specified in the metadata list, the column is skipped.
/// If the current data row does not contain a field specified in the metadata list but the source row does,
/// the column is added to the current row, supporting schema evolution.
/// </summary>
/// <param name="currentDataRow">Current data row.</param>
/// <param name="sourceDataRow">Source data row.</param>
/// <param name="listOfColumnMetadata">List of column metadata defining which columns to copy. Usually it is the list of column metadata or the source data table</param>
public static void CopyFrom(this IDataRow? currentDataRow, IDataRow sourceDataRow, IList<IColumnMetadata> listOfColumnMetadata)

Namespace and Assembly

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

Behavior

Usage Example

Assume two data tables with partially overlapping schemas:

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

// Create EmploymentType data table without Description column
IDataTable employmentTypeDataTable = dataSet.AddNewTable("EmploymentType");
employmentTypeDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeDataTable.AddColumn("Code", DataTypeNames.STRING);

// Add current data row to it
IDataRow employmentTypeCurrentDataRow = employmentTypeDataTable.AddNewRow();

// 2. Create refreshed data set
IDataSet refreshedDataSet = DataSetFactory.CreateDataSet();

// Create EmploymentType data table with Description column and refreshed data
IDataTable employmentTypeRefreshedTable = refreshedDataSet.AddNewTable("EmploymentType");
employmentTypeRefreshedTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeRefreshedTable.AddColumn("Code", DataTypeNames.STRING);
employmentTypeRefreshedTable.AddColumn("Description", DataTypeNames.STRING);

IDataRow employmentTypeRefreshedDataRow = employmentTypeRefreshedTable.AddNewRow();
employmentTypeRefreshedDataRow["Id"] = 1;
employmentTypeRefreshedDataRow["Code"] = "ET01";
employmentTypeRefreshedDataRow["Description"] = "Part Time";

// Call CopyFrom method and observe that employmentTypeCurrentDataRow contains "Description" field with "Part Time" value
employmentTypeCurrentDataRow.CopyFrom(employmentTypeRefreshedDataRow, employmentTypeRefreshedTable.Columns);

Typical Use Cases

 

Table of Content POCO DataSet DataRow 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.