This documentation is archived and is not being maintained.

Adding Tables to an Existing Dataset

Visual Studio .NET 2003

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

  1. In the form or component you are working with, add a data adapter that references the table you want to add.
  2. Select the data adapter, and then from the Data menu, choose Generate Dataset.

    The Generate Dataset dialog box is displayed.

  3. Under Choose a Dataset, choose Existing, and then select the name of the dataset to add the table to.
  4. 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.
  5. 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.
  6. 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.

See Also

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)