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