Monday, April 16, 2012

DataTable.Copy Vs 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 targetTable;
targetTable = sourceTable.Clone();

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

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

Here, the targetTable is created with a copy of the structure and data from the sourceTable
targetTable.Rows.Count() returns the number of rows which were present in the sourceTable.

That’s it, we have seen the difference between DataTable.Copy() and DataTable.Clone()

Search Flipkart Products:
Flipkart.com

2 comments:

lingmaaki said...

clone and copy example with source code

http://net-informations.com/faq/framework/clone-copy.htm

ling.

joy said...

One thing I learned in life is to love what makes you happy and to cherish every moment you spend with your family, friends or love ones because everything that we have now on earth is temporary. Well, thank you for inspiring us with your great art work.
Visit my site for a very wonderful offer.

n8fan.net