Figure 8. TableAdapter Configuration Wizard: The first screen of the TableAdapter Configuration Wizard prompts you to select a data connection.

Right-click the designer surface to open a context menu, and then choose "Add --> Table Adapter." This opens the TableAdapter Configuration Wizard (see Figure 8).

Figure 9. Command Type Selection: For this example, leave the first choice (Use SQL statements) selected as the command type.

You've already established a connection to the AdventureWorks database; just make sure it is selected in the drop-down box, and then select Next to get to the command type selection screen (see Figure 9).

Select Next from the Command Type Selection screen, and you will be prompted to enter a query. Copy this SQL text into the wizard then select Finish.

Author's Note: The preceding code is a slightly pared down version of the query used to generate the Sales.vIndividualCustomer view in the AdventureWorks DB. You could generate the query yourself in SqlServer 2005 Management Studio Express by opening the context menu for the view and selecting Script View As --> Create To --> New Query Editor Window.)

The wizard will close and you'll see a table on the dataset designer surface. Go to the Properties pane and change the name from the default DataTable1 to CustomerTable. Your screen should resemble Figure 10.

Figure 10. Adding a TableAdapter: The figure shows the Dataset Designer with the successfully created CustomerTable table adapter.

VS has taken the liberty of defining the first field (CustomerID) as the primary key, designated with a small key icon in the table. For this query, though, that is not sufficient to uniquely define rows in the data; if you used the default, you'd get a key violation at runtime. To avoid that, select both the CustomerID and the AddressLine1 fields, right-click to open the context menu, and choose "Set Primary Key." You should see key icons next to both fields.