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.

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:


Cindy said...

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


lingmaaki said...

clone and copy example with source code


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

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.


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.

Leslie Lim said...

I love this post, and I was absolutely thrilled to see the other links that you published that go along with this topic. Thank you for sharing your thoughts. I am happy to be a new follower. :)