You need to copy an existing schema and data
Use one of the following techniques:
Copy( ) method of the
DataTable when all of the data for a table needs
to be copied.
Clone( ) method of the
DataTable to create the schema for each table in
DataSet when only a subset of the
data needs to be copied. You can use the
ImportRows( ) method of the
DataTable to copy the
subset of rows from the source to the destination table.
Once the destination tables are created and the data is copied into
them, the example shows how to create the
DataRelation objects from the source
DataSet in the destination
The sample code contains two event handlers:
Sets up the sample by creating a
containing the Orders and Order Details tables from Northwind and a
relation between the two tables. The default view for the Orders
table is bound to a data grid on the form.
Creates a destination
DataSet and copies the
schema and specified data into it from the source
DataSet created in the
Form.Load event handler.
The C# code is shown in Example 5-2.
Example 5-2. File: CopyTablesBetweenDataSetsForm.cs
// Namespaces, variables, and constants using System; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; // Table name constants private const String ORDERS_TABLE = "Orders"; private const String ORDERDETAILS_TABLE ...