Partilhar via


How to: Connect to an Access Database Using the AccessDataSource Control

You can connect the AccessDataSource control to a Microsoft Access database and then display or edit data using controls such as the GridView control.

To use the AccessDataSource control to connect to an Access database

  1. Open the page from which you want to connect to an Access database.

  2. Switch to Design view.

  3. From the Data group on the Toolbox, drag an AccessDataSource control onto your page.

  4. If the Smart Tag panel is not displayed, right-click the control and click Show Smart Tag.

  5. In the AccessDataSource Tasks list, click Configure Data Source.

    The Configure Data Source wizard is displayed.

  6. In the Choose a Database pane, type or select the path to your Microsoft Access database, which will have .mdb as the file name extension.

    Note

    We recommend that you store your Access database in the Web site's App_Data folder to ensure that the Web server will not return the .mdb file in response to a Web request. In addition, for local Web sites, Visual Web Developer ensures that the Web server has permissions to read and write files in the App_Data folder. For Web sites on other computers, you will need to set those permissions manually.

  7. Click Next.

  8. In the Configure the Select Statement pane, if you want to use the wizard to create a SQL query, click Specify columns from a table or view and use the options in the pane to configure your query.

    Note

    To have the wizard generate Insert, Update, and Delete statements based on the Select statement you are creating, click Advanced.

  9. If you want to use the query builder or write your Select query, click Specify a custom SQL statement or stored procedure, click Next, and then write your SQL statement. Click the UPDATE, INSERT, or DELETE tabs to create update statements.

  10. Click Next.

  11. In the Test Query pane, click Test Query to determine whether the query returns the results you want.

  12. Click Finish.

    You can now bind data controls such as the GridView control to the AccessDataSource control.

See Also

Tasks

Walkthrough: Basic Data Access in Web Pages

Walkthrough: Creating a Web Page to Display Access Database Data

Concepts

Data Source Controls Overview

Other Resources

AccessDataSource Web Server Control Overview