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 other Products:
Flipkart.com

5 comments:

Cindy said...

Why clone humans, reasons against cloning. Click www.gofastek.com for more information.

Cindy
www.gofastek.com

lingmaaki said...

clone and copy example with source code

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

ling.

Lee Shin said...

spot on with this write-up, i like the way you discuss the things. i'm impressed, i must say. i'll probably be back again to read more. thanks for sharing this with us.

Lee Shin
www.trendone.net

Aissa said...

Nice post. Thank you for taking the time to publish this information very informative; so happy to be given a privilege to post a comment here.

aissa
www.joeydavila.net

sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


edupdf.org