6.2. Using the SqlDataSource Control

The SQLDataSource control is a user-friendly way of working with Microsoft's ADO.NET data handling technology. It does much of the grunt work for you, such as opening a connection to the database, executing a SQL statement, fetching the data, and closing the data connection.

6.2.1. Adding and configuring a SqlDataSource control

You need a working SqlDataSource control so that other controls, such as GridView, FormView, and ListView, can use it for their data needs. To add a SqlDataSource control to your page, follow these steps:

  1. Add a single file ASP.NET Web Form (don't use the Place Code in Separate File option) called starter.aspx to your project.

  2. Drag a SqlDataSource control from the Data category of the Toolbox and drop it on the page.

  3. Click the Smart Tag button and select Configure Data Source.

    The Configure Data Source Wizard appears.

  4. From the drop-down list, choose the northwnd.mdf data connection and then click Next.

  5. Accept (that is, leave checked) the offer to save the connection string in the Save the Connection String screen, and then click Next.

  6. In the Configure the Select Statement dialog box, choose the Customers table from the drop-down list.

    The columns (fields) in the Customers table appear in the Columns box.

  7. In the Columns box, select the check box for the asterisk.

    This indicates that you want to select all the columns for the query.

  8. Click the Advanced button.

    The Advanced SQL Generation Options dialog box appears, as shown in Figure ...

Get ASP.NET 3.5 For Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.