Difference between dataset clone & dataset copy

Posted by Udaysimha under Interview Questions on 1/18/2012 | Points: 10 | Views : 5310 | Status : [Member] | Replies : 2
Hi All,
Please let me know What are all the differences between dataset clone and dataset copy.
Thanks

uday


Responses

Posted by: Blessyjees on: 1/18/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Clone: Copies only the structure of the dataset. It includes the schema of all datatables and their constraints and excluding data in the tables.
Copy. Copies the structure of the dataset along with its data.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanthlaxmi on: 1/18/2012 [Member] Starter | Points: 25

Up
0
Down
DataSet.Clone method copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. But it does not copy any data.

Whereas, DataSet.Copy method copies both the structure and data.

Following is how you would create a clone of an existing dataset: -
[C#]
private DataSet CreateClone(DataSet myDataSet) {

DataSet myCloneDS;
myCloneDS = myDataSet.Clone();
return myCloneDS;
}



Now, to get the filtered rows into your cloned dataset see the following code: -
[C#]
private DataSet CreateClone(DataSet myDataSet, string myTable, string myCol, decimal myValue) {

DataSet myCloneDS;
myCloneDS = myDataSet.Clone();


DataRow[] copyRows = myDataSet.Tables[myTable].Select(myCol + " = " + myValue);
DataTable custTable = myCloneDS.Tables[myTable];

//Insert into all filtered row data into the cloned Dataset
foreach (DataRow copyRow in copyRows)
custTable.ImportRow(copyRow);

return myCloneDS;
}


If this helps you .
Please "Mark as Answer"

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response