Adding Tables to an Existing Dataset
Occasionally you might need to add a data table to a dataset that has already been generated. One way is to delete the dataset and regenerate it manually to include the new table. However, in that case you might lose additional dataset information (including constraints and DataRelation objects) that were added to the dataset after it was generated.
You can add tables to an existing dataset two ways:
- Use the Component Designer in a form or component. This is an easy solution that allows you to drag elements onto the form or component and then regenerate a modified dataset.
- Use the XML Designer to modify the dataset schema. This strategy is useful if you are comfortable using the XML Designer and do not want or need to open a form or component. Adding a table using the XML Designer is similar to creating the schema manually. For more information, see Creating Tables in XML Schemas.
To add a table to an existing dataset using the Component Designer
- In the form or component you are working with, add a data adapter that references the table you want to add.
- Select the data adapter, and then from the Data menu, choose Generate Dataset.
The Generate Dataset dialog box is displayed.
- Under Choose a Dataset, choose Existing, and then select the name of the dataset to add the table to.
- Under Choose which table(s) to add to the dataset, select the names of all the tables that you want to add to the dataset. The list includes tables from all available data adapters.
- If you want to create an instance of the modified dataset on your form or component, select Add an instance of this dataset to the designer.
- Click OK to generate an updated dataset.
Information about the added table is added to the dataset schema and to the derived dataset class file. Existing information (including tables, constraints, and relationships) is left intact.
Creating Typed Datasets with the Component Designer | Relationships in ADO.NET Datasets | Creating Tables in XML Schemas | Adding a DataTable to a DataSet | Code: Adding Two Related DataTables to a DataSet (Visual Basic)