Export (0) Print
Expand All

Walkthrough: Connecting to Data in an Access Database (Windows Forms)

Connecting your Visual Studio application to data in an Access database is simplified with the Data Source Configuration Wizard. After you complete the wizard, data is available in the Data Sources Window for dragging onto your forms. For more information, see Local Data Overview. When connecting to data in local data files it is important to understand how the project system in Visual Studio manages these files. For more information, see How to: Manage Local Data Files in Your Project.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

Tasks illustrated in this walkthrough include:

  • Creating a new Windows Application project.

  • Creating and configuring a dataset in your application based on the Customers and Orders table in the Northwind database using the Data Source Configuration Wizard.

In order to complete this walkthrough, you need:

To create the new Windows Application project

  1. From the File menu, create a new project.

  2. Select Windows Application and click OK. For more information, see Developing Client Applications.

    The project is created and added to Solution Explorer.

You create the dataset by running the Data Source Configuration Wizard.

To create the dataset

  1. On the Data menu, click Show Data Sources.

  2. In the Data Sources window, click Add New Data Source.

  3. Select Database on the Choose a Data Source Type page. Click Next.

  4. Select Dataset on the Choose a Database Model page. Click Next.

  5. On the Choose your Data Connection page, select New Connection to configure a new data connection.

  6. In the Add Connection dialog box, enter the path to the Northwind.mdb database file, or click the Browse button to locate the Northwind.mdb file. For information on obtaining a copy of the Northwind.mdb file, see How to: Install Sample Databases. Click OK.

    Note Note

    If the Data source is not Microsoft Access Database File (OLE DB), then select Change to open the Change Data Source dialog box and change that value.

  7. Click Next on the Choose your Data Connection page.

  8. Click Next on the Save connection string to the Application Configuration file page.

  9. Expand the Tables node on the Choose your Database Objects page.

  10. Select the Customers and Orders tables, and then click Finish.

    The NorthwindDataSet is added to your project and the Customers and Orders tables appear in the Data Sources window.

Storing sensitive information (such as a password) can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see Protecting Connection Information (ADO.NET).

The dataset you just created is now available in the Data Sources window.

To add functionality to your application

Show:
© 2014 Microsoft