... all I'm offering is the truth. Nothing more. RSS 2.0
# Tuesday, January 01, 2008

I was looking at the DataSet object the other day and realized that there is both a Copy and a Clone methods. They are designed to fulfil similar functions which the following code highlights.

The Clone method is designed to only copy the structure i.e. the schema, relations and constraints.

The Copy method is designed to replicate the structure and the associated data.

DataSet data1 = new DataSet();
DataSet data2 = new DataSet();

System.IO.FileStream fs = new System.IO.FileStream(@"C:\test\test.xml", System.IO.FileMode.Open);
data1.ReadXml(fs);

data2 = data1.Clone();
foreach (DataRow dr in data2.Tables[1].Rows)
{
    Console.WriteLine(dr[0].ToString()); // We called the Clone method
}

 

data2 = data1.Copy();
foreach (DataRow dr in data2.Tables[1].Rows)
{
    Console.WriteLine(dr[0].ToString());
}

 

Technorati tags: , ,
Tuesday, January 01, 2008 2:11:01 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
.NET | C#
Blogroll
Statistics
Total Posts: 335
This Year: 23
This Month: 1
This Week: 1
Comments: 32
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Mark Downie
Sign In
All Content © 2010, Mark Downie
DasBlog theme 'Business' created by Christoph De Baene (delarou)