Walkthrough: Connecting to Data in an Access Database
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.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. 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:
- Access to the Northwind sample database Access file (northwind.mdb). For more information, see How to: Install Sample Databases.
Creating the Project
To create the new Windows Application project
From the File menu, create a new project.
Select Windows Application and click OK. For more information, see Creating Windows-Based Applications.
The project is created and added to Solution Explorer.
Creating the Dataset
You create the dataset by running the Data Source Configuration Wizard.
To create the dataset
On the Data menu, click Show Data Sources.
In the Data Sources window, click Add New Data Source.
Select Database on the Choose a Data Source Type page. Click Next.
On the Choose your Data Connection page, select New Connection to configure a new data connection.
In the Choose Data Source dialog box, select Microsoft Access Database File. Click Continue.
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.
Click Next on the Choose your Data Connection page.
Click Next on the Save connection string to the Application Configuration file page.
Expand the Tables node on the Choose your Database Objects page.
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
Select items in the Data Sources window and drag them onto your form. For more information, see Displaying Data Overview.
Open the data source in the Dataset Designer to add or edit the objects that make up the dataset.
Corrected the steps in the “To create the dataset” procedure.