tailieunhanh - Murach’s ado net _4 database programming with vb 2010 phần 3

Một vài năm trước đây, một khách hàng đã sử dụng thuật ngữ "các trang kết hợp" để mô tả phong cách trình bày của chúng tôi, và tên đã bị mắc kẹt. Nó có nghĩa là cuốn sách này trình bày từng chủ đề trong một hai trang. Trang bên phải cho ảnh chụp màn hình, mã số, cú pháp,. | 128 Section 2 How to use data sources and datasets for Rapid Application Development How to use a DataGridView control to create a Master Detail form A form that displays the data from a main table and a related table is commonly referred to as a Master Detail form. Figure 4-14 shows how to use a DataGridView control to create a Master Detail form. In this example the main table is the Vendors table and the related table is the Invoices table. The first thing you should notice in this figure is the Data Sources window. Although you would expect the data source for this form to include both the Vendors and Invoices tables the Invoices table shows up twice in the Data Sources window. Ffrst it shows up separately from the Vendors table. Second it shows up subordinate to the Vendors table. This subordinate entry indicates that the Vendors and Invoices tables have a one-to-many relationship with each other. It s this relationship which is based on the VendorlD column in each table that Visual Studio uses to generate a DataGridView control that displays the appropriate data. To create a DataGridView control that displays data from a table that s related to the main table for a form you simply drag the subordinate table to the form. When you do Visual Studio generates the DataGridView control along with the appropriate Bindingsource and TableAdapter objects. In addition it sets the properties of the Bindingsource object so the data from the related table will be displayed. To understand how this works this figure also presents the properties of the Bindingsource object that accomplish the binding for the DataGridView control. First instead of naming a dataset the DataSource property names the binding source for the main table. Second instead of naming a data table the DataMember property names the foreign key that relates the two tables. In this figure for example the DataSource property of the InvoicesBindingSource object is set to VendorsBindingSource and the DataMember