How to: Display Related Data on a Form
Data in separate tables can be related. When related data is in two tables, the relationship is visible in the Data Sources window. For example, if you connect to the sample Northwind database and expand the Products table, you will see that an Order Details table is displayed as part of the Products table. If you drag this Order Details table or one or more of its fields to a Windows Form, it is displayed as part of a relationship with the Products table. For example, if you scroll through the products in the Products table, the corresponding order information for each product is automatically displayed.
To display related data on a form
On the File menu, click New Project.
In the New Project dialog box, click Windows Application, and then click OK.
A new Windows Forms project opens.
Add a connection to the sample database named Northwind.sdf as described in How to: Connect to a Database (C#).
On the Data menu, click Show Data Sources.
The Data Sources window opens.
In the Data Sources window, expand NorthwindDataSet, and then expand Products.
Click the drop-down arrow next to Product Name, and then click Label.
Drag the Product Name field to the Windows Form.
Drag the Order Details table (the one that is located in the Products table) to the form, and position it under the label.
A DataGridView control is added to the form.
Press F5 to run the program.
When the application opens, click the Move Next Item button on the ProductsBindingNavigator at the top of the form.
Verify that the order detail information in the DataGridView control is updated whenever the product changes.