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.
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:
Access to the Northwind sample database Access file (northwind.mdb). For more information, see How to: Install Sample Databases.
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.
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.
Select Dataset on the Choose a Database Model page. Click Next.
On the Choose your Data Connection page, select New Connection to configure a new data connection.
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.
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.
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 Binding Windows Forms Controls to Data in Visual Studio.
Open the data source in the Dataset Designer to add or edit the objects that make up the dataset.