Friday, August 31, 2012

Difference between Data table Copy and the Clone method


Data table Copy and the Clone method:
"Both the Copy and the Clone methods create a new Data Table with the same structure as the original Data Table. The new Data Table created by the Copy method has the same set of Data Rows as the original table, but the new Data Table created by the Clone method does not contain any Data Rows."

In summary, Clone method creates a new Data Table with same structure and constraints but without data and Copy method does same but includes data too.

Copy 

datatable newTableCopy;
newTableCopy= existingTable.Copy();

datatable.copy : 
Creates a new datatable along with same structure - (schemas and constraints applied if any) including data in the existing table.

Clone

datatable newTableClone;
newTableClone= existingTable.Clone();.

datatable.Clone():

Creates a new datatable along with same structure with all schemas and constraints excluding data

No comments:

Post a Comment