Saturday 10 May 2014

Differece between ds.clone and ds.copy?

The Clone method of the DataSet class copies only the schema of a DataSet object. It returns a new DataSet object that has the same schema as the existing DataSet object, including all DataTable schemas, relations, and constraints. It does not copy any data from the existing DataSet object into the new DataSet. 

The Copy method of the DataSet class copies both the structure and data of a DataSet object. It returns a new DataSet object having the same structure (including all DataTable schemas, relations, and constraints) and data as the existing DataSet object.

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; }