Creating Typed Datasets with the Component Designer
When you are using a dataset with a form or component, you can use the Component Designer to define the dataset schema and class file. You can then add an instance of the dataset to the form or component you are working with.
When you are editing a form, the Component Designer appears as a tray at the bottom of the designer window. The tray opens automatically as soon as you add a component or nonvisual control to the form. Instances of dataset classes are displayed there, where you can select them in order to set properties or write event handlers for them.
To create a dataset in the Component Designer
- Add one or more data adapters to the form or component that specify what data you want to put in the dataset. For more information, see Creating Data Adapters.
- In the Component Designer, select the adapter or adapters that will be used to transfer data between the data source and the dataset.
Typically, each data adapter accesses data in a single table. Therefore, to create a dataset containing multiple data tables, you should select all the adapters for the tables you want to work with.Note Adding multiple tables to the dataset does not automatically create a relationship between the tables; you must do that manually after creating the dataset. For more information, see Creating DataRelation Objects with the XML Designer.
- From the Data menu, choose Generate Dataset.
The Generate DataSet dialog box appears.
- Select New and then specify a name for the new dataset. If you want to add the dataset to your form or component, click Add an instance of this DataSet to the designer.
Visual Studio uses the information in the data adapters to generate an XML Schema file (.xsd), which is added to the project using the name you specified. Visual Studio then generates a new dataset class file based on the schema.Note The new dataset class file is visible in Solution Explorer only if you select Show All Files.
If you indicated that you wanted an instance of the dataset, the instance is added to the form or component using the name you specified with a numeric suffix. For example, if you named the dataset dsAuthors, the instance is named dsAuthors1.Note If you accept the default dataset name of DataSet1, the instance in your form or component will be named DataSet11 because of the numeric suffix that is automatically added.
- If you added a dataset to the form or component, add code to populate it. Most frequently, you do this by calling the Fill method of the data adapters. For more information, see Populating a DataSet from a DataAdapter.
- If you want to update the dataset and database, add code to the form or component to do so. For more information about updating, see Dataset Updates in Visual Studio .NET.
Creating XML Schemas and Datasets | Introduction to DataRelation Objects | Adding Tables to an Existing Dataset | Creating Data Adapters | Adding Untyped Datasets to a Form or Component | Adding Existing Typed Datasets to a Form or Component | Walkthrough: Creating a Distributed Application | Data Walkthroughs