Browsing multiple related tables in a ado.net DataSet (2)

Source: Internet
Author: User
Tags connect visual studio
ado| Data Creation Application
This section establishes the starting point for this walkthrough. The following steps create data connections, data adapters, and datasets that contain related tables, as well as several controls that select and display data.

Creating a new Windows application

From the File menu, point to New (new), and select Project. The New Project dialog box appears.
In the Project Types pane, select the Visual Basic Projects (Visual Basic project) or Visual C # Projects (Visual C # project), depending on the programming language you want.
In the Templates pane, select Windows Application (Windows application) and name it datarelationexample, and then click OK.
The Datarelationexample project is added to Solution Explorer (Solution Explorer).

Connecting to a database
This connection allows you to communicate with a data source in the Visual studio® integrated Development Environment (IDE).

Connecting to the Northwind sample database in Server Explorer (Server Explorer)

In Server Explorer, establish a data connection that connects to the Northwind sample database.
In Server Explorer, expand the Northwind data connection until you can see all the tables.
Creating data Adapters and connections
This step creates connections and data adapters that are used to connect and exchange data between applications and data sources.

Creating data Adapters and connections

Drag the Customers table from the Server Explorer (Server Explorer) onto the form. The connection and data adapters are displayed in the component tray.
Select Connection (Connect) and set the Name property to Dcnorthwind.
Select the data adapter and set the Name property to Dacustomers.
Drag the Orders table from the Server Explorer (Server Explorer) onto the form. A second data adapter appears in the component tray.
Select the new data adapter and set the Name property to Daorders.
To generate data sets
Use the data adapter that you just added to the form to generate a dataset that contains customer tables and order tables.

Generate datasets that will contain related data tables

From the Data menu, select the Generate DataSet (the build dataset). The Generate DataSet (Generate DataSet) dialog box is displayed.
Tip: Move the cursor over the form to use the Data menu.
Click New (new) and name the DataSet DsNorthwind.
Select the Customer table and order table.
Select the Add this dataset to the designer (add the dataset to the designer) check box, and then click OK.
A file named Dsnorthwind.xsd will be added to the project in Solution Explorer (Solution Explorer), and an instance of the dataset will be displayed in the component tray.

Create a relationship
Generating a dataset does not automatically create relationships between the tables in the dataset. Relationships can be created programmatically, or you can use XML Designer (XML Designer) to create them visually. This article uses XML Designer (XML Designer).

Create a relationship between a customer table and an order table

In Solution Explorer (Solution Explorer), double-click the Dsnorthwind.xsd file. The file opens in the XML Designer (XML Designer).
From the XML Schema (XML Schemas) tab of the toolbar, drag the relation (relationship) onto the order table.
In the Edit Relation dialog box, set the following properties:

Element settings
Name CustomersOrders
Parent Customers
Child Orders
Key Fields CustomerID
Foreign Key Fields CustomerID


Click OK to create the relationship and close the dialog box.
From the File menu, select Save All to save the project.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.