Monday, August 27, 2012

Difference between DataTable.Copy and DataTable.Clone


Both the methods DataTable.Clone and DataTable.Copyare are used to make copies of existing datatables, the difference is

DataTable.Clone() - Copies only the structure of the source table with the constraints, the data is not copied from the source table.

DataTable.Copy() - Copies the structure and data from the source table.


Example: 
DataTable.Clone()
DataTable dt;
dt= sourceTable.Clone();

Here, the targetTable is created with only the structure of the sourceTable
targetTable.Rows.Count() returns 0.

Example: DataTable.Copy()
DataTable dt;
dt= sourceTable.Copy();

No comments:

Post a Comment