DataSet.Copy() and DataSet.Clone()

DataSet.Copy() : Copies both the structure (tables, relations etc) and the data.

DataSet.Clone() : Copies Only the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

e.g.

DataTable table1 = new DataTable(“Employee”);

table1.Columns.Add(“Name”);

table1.Columns.Add(“EmpId”);

table1.Rows.Add(“XYZ”, 1);

DataTable table2 = new DataTable(“Projects”);

table2.Columns.Add(“EmpId”);

table2.Columns.Add(“ProjectAllocated”);

table2.Rows.Add(1, “ProjectOne”);

// Create a DataSet.

DataSet set = new DataSet(“Office”);

set.Tables.Add(table1);

set.Tables.Add(table2);

  // Copy the DataSet.

DataSet copyDataSet = set.Copy();

// Get a clone of the original DataSet.

DataSet cloneSet = dataSet.Clone();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s