Figure 6.23: Creating a relationship between two tables
Note Remember: You're unselecting these columns, so you uncheck the columns for the
Orders table.
Figure 6.24
shows the completed dialog box with the selected columns to display from
each table.
Figure 6.24: Selecting the columns to display from each table
8. Click the Next button to proceed.
9. Select the display style for the rows (also known as records) in the parent table
that are displayed in your form. You can display the rows in a grid, or you can
display each column using a separate control. You'll use a separate control for the
columns, so select the Single Record in individual controls radio button. The other
check boxes in the dialog box allow you pick the controls you want to add to your
form. These controls affect the rows in the master table, and you can add the
following controls to your form:
Note In this example, the parent table is the Customers table, and the child table is
the Orders table. The rows for the child table are displayed in a DataGrid
control.
o
Cancel All The Cancel All button allows you to undo any changes you've
made to the current row.
o
Add The Add button allows you to add a new row.
o
Delete The Delete button allows you to delete the current row.
o
Cancel The Cancel button allows you to cancel a change made to the
control, you select the control in the form designer and expand the DataBindings
properties in the Properties window. You'll see these properties in the Data area of the
Properties window.
Next, you'll see how the text box for the Customer ID is set. Select the text box to the
right of the CustomerID label in your form; this text box is named editCustomerID. Make
sure the DataBindings properties are expanded in the Properties window. Finally, click
the drop-down list for the Text property to view the current column to which the text box
is bound. As you can see from Figure 6.27
, editCustomerID is bound to the CustomerID
column of the Customers table. This means that when you run the form and load data
from the database, the CustomerID column value will be displayed in the editCustomerID
text box.
Figure 6.27: The editCustomerID text box is bound to the CustomerID column
In the next section
, you'll add a label and a text-box control to display the City column in
your form.
Adding Controls to the Form
When you ran the Data Form Wizard earlier to create your form, you'll recall that I told
you to unselect the City column of the Customers table so that it didn't appear on your
form. I asked you to do this so that you can now see how to manually add a control and
bind it to the City column. That way, you can see how to build your own forms that
access the database.
Follow these steps to add a label and a text box to your form:
1. Add a label below the Address label in your form. Set the Name property for your
new label to lblCity.
2. Set the Text property for your label to City.
3. Next, add a text box below the editAddress text box.
4. Set the Name property for your new text box to editCity.
5. Remove the current text from the Text property so that no default text is shown in