Connecting to an Ms-Access 2003 database file using Visual Basic 2008 Express Edition

The simplest way to retrieve a data from an Ms-Access 2003 database file in VB 2008 Express Edition is to use Database Explorer. Database Explorer is a database management tool that enables user to access server-based or local-based databases. There are other handy database access tools such as OleDbDataAdapter or SqlDataAdapter but I prefer using Database Explorer because it is simpler to use and it allows you to link to a database file conveniently and effortlessly.

To connect to an Ms-Access database file, you should first specify the location and file name of the database file that you wanted to link to. The following steps show you how:

1. Create an Ms-Access 2003 database file.(If you are familiar with database programming, this one is just common sense to you).

2. Start Visual Basic 2008 Express Edition.

3. Click File>New Projects>Select Windows Forms Application from the Visual Studio installed templates option>Click the Ok button.
This will display a blank form on the screen.

4. Next, click the View menu>Select Database Explorer. This will display the Database Explorer panel on the left portion of your VB 2008 Express Edition Integrated Development Environment. Alternatively, you can press CTRL+ALT+S.

5.In the Database explorer panel, locate the Add Connections option>Right-click it, then select Add connection…

6. The Add Connection Dialog box will appear. Click the Change… button beside the data source label>Select Microsoft Access Database File form the data source list box>Click Ok.

7. Click the Browse… button beside the Database file name label then locate and double-click your (Ms-Access database file).mdb file>Click Ok.

Click the Test Connection button to test if the database connection is working properly. Just make sure that you database file is not password protected or else you will get a “Not a valid Password” error.

After choosing the file name of the Ms-Access file that you wanted to connect to, you will need to select the data source or the data that you wanted to work with your application. Data sources can be made from a database application such as Ms-Access, or from a web server.

To define the data source, follow these steps:

1.Click the Data menu>Click the Add new data source… option.

This will bring out the Data Source Configuration Wizard. Since we will be getting our data from a database application and not from a web-server and definitely not from any bound object embedded on a form,select database>Click the Next button.

2.In the next screen, you will see your database file name in the Data Connection list box>Just click the next button.

3. After clicking the next button, a message box containing the following prompt will appear:
“The connection you selected uses a local data file that is not in the current project. Would you like to copy the file to you project and modify the connection?
If you copy the file to your project, blah blah blah”. Just click the Yes button.

4.The connection string dialog box will appear. A connection string is simply a string containing information about the connection.Just click the Next button.

5.The Database object screen will be shown containing a tree control with Tables and Views parent items. Tables contains your actual table while Views stores virtual tables,To manipulate your actual table, just expand the Tables parent item, and check the table that you wanted to be available in you project. Alternatively, you can check the Tables parent item if you wanted all you tables to be made available on your project.

6.Finally, click Finish.

After designating the table where you wanted to get your records from, the next thing that you need to do is to show the record values on your form. These steps teach you how:

1.Click the Data menu> Select Show Data Sources. This will show the available data sources or tables in a tree control. Alternatively, you can also press Shift+Alt+D.

2. In the Data Sources Panel, expand the table that you wanted to view the data in a form>Click and drag the individual fieldnames from the data sources panel to your form.

3. A bound control will be displayed for each field name. Together with a binding navigator that contains next, top, bottom, previous, add, delete, and save buttons.

4. Press F5 to run your application.

Try to click any of the navigational buttons and see how they worked perfectly like a charm. If you missed any of the steps during the connection process then your application will definitely fail. But don't despair, as Henry Ford once said, "Failure is simply the opportunity to begin again, this time more intelligently".