Before we start writing any code to connect to the database, it is important to understand some of the objects that you will be using and their storage locations within the Namespace hierarchy.
In order to start working with databases you first need to ensure that you have a reference to the System.Data object. To do this, select the Add Reference menu option from the Project menu and scroll down to the System.Data entry. Once you have added this reference, we can then take a closer look at what is offered via this object and also look at some of the methods we will be using in this part of the article.
Now, some of you may already know this, but there is a very nice tool in Visual Studio called the Object Browser. This tool isn't new to Visual Studio.NET but has been available in versions of Visual Basic as far back as I can remember. To access this tool, select the Object Browser menu option from the View menu. The Object Browser allows you to look at all objects referenced by your application and to drill down and look at the methods and properties that are exposed by those objects. Well designed objects will also have information in the form of remarks and descriptions that you can view when selecting a method or property.
So, with the Object Browser open, you should see the System.Data entry. If you expand the node you will see the available objects exposed by the System.Data object. The first point of interest is the sub node System.Data, this object houses all of the generic data objects that you will undoubtably use when working with databases. These objects include the DataSet, DataTable and DataView objects that you may already be familiar with.
The next point of interest are the different data provider objects that are available, such as System.Data.OleDb and System.Data.SqlClient. The System.Data.OleDb object contains objects that allow you to work with database that are oleDb compatible, such as Microsoft Access and mySQL. The System.Data.SqlClient object is an object that is specifically written to work with Microsoft SQL Server databases. There is also an System.Data.Odbc object should you need to work with databases via ODBC. As this part of the article is using an Microsoft Access database, we will concentrate on the System.Data.OleDb object from this point on, but when we reach Part Three of this article (using Microsoft SQL Server) you will see that the System.Data.SqlClient object is very similar to the System.Data.OleDb object).
If you expand the System.Data.OleDb node you will be presented with a list of the objects exposed. For this section of the tutorial we will be using the OleDbConnection and the OleDbDataAdapter objects to connect and retrieve an initial set of data from the database. By selecting the OleDbConnection node entry you will see the available methods and properties of this object as indicated in the following screen shot:
The OleDbConnection object in the Object Browser
As you can see in the above screen shot, I have selected the New(string) method, this is an overloaded constructor which as the summary states, initialises an instance of the connection object using a specified connection string.
If this is the first time that you have used the Object Browser, I recommend that you take some time to get to know it as it will undoubtedly aid you in your work.