Walkthrough: Creating a Dataset with the Dataset Designer
In this walkthrough you will create a dataset using the Dataset Designer. It will take you through the process of creating a new project and adding a new DataSet item to it. You will learn how to create tables based on tables in a database without using a wizard.
Tasks illustrated in this walkthrough include:
Creating a new Windows Application project.
Adding an empty DataSet item to the project.
Creating and configuring a data source in your application by building a dataset with the Dataset Designer.
Creating a connection to the Northwind database in Server Explorer.
Creating tables with TableAdapters in the dataset based on tables in the database.
Notitie
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.
In order to complete this walkthrough, you need:
- Access to the Northwind sample database (SQL Server or Access version). For more information, see How to: Install Sample Databases.
From the File menu, create a new project.
Choose a programming language in the Project Types pane.
Click Windows Application in the Templates pane.
Name the project DatasetDesignerWalkthrough, and then click OK.
Visual Studio will add the project to Solution Explorer and display a new form in the designer.
On the Project menu, click Add New Item.
The Add New Item dialog box appears.
In the Templates box of the Add New Item dialog box, click DataSet.
Name the Dataset NorthwindDataset, and then click Add.
Visual Studio will add a file called NorthwindDataset.xsd to the project and open it in the Dataset Designer.
On the View menu, click Server Explorer.
In Server Explorer, click the Connect to Database button.
Create a connection to the Northwind sample database.
Notitie
You can connect to the SQL Server or Access version of Northwind for this walkthrough.
This section will explain how to add tables to the dataset.
Expand the data connection you created in Server Explorer, and then expand the Tables node.
Drag the Customers table from Server Explorer onto the Dataset Designer.
A Customers data table and CustomersTableAdapter are added to the dataset.
Drag the Orders table from Server Explorer onto the Dataset Designer.
An Orders data table, OrdersTableAdapter, and data relation between the Customers and Orders tables are added to the dataset.
Drag the Order Details table from Server Explorer onto the Dataset Designer.
An Order Details data table, Order DetailsTableAdapter, and a data relation between the Orders and Order Details tables are added to the dataset.
Save the dataset.
Select items in the Data Sources window and drag them onto a form. For more information, see Binding Windows Forms Controls to Data in Visual Studio.
Add more queries to the TableAdapters. For more information, see How to: Create TableAdapter Queries.
Add validation logic to the ColumnChanging or RowChanging events of the data tables in the dataset. For more information, see Validating Data in Datasets.
Binding Windows Forms Controls to Data in Visual Studio
Preparing Your Application to Receive Data
Fetching Data into Your Application
Binding Controls to Data in Visual Studio