Difference between revisions of "Accessing Databases Using Visual Basic"

From Techotopia
Jump to: navigation, search
Line 4: Line 4:
  
 
The chapter assumes that you have Microsoft Access installed together with the "NorthWind" sample Access database. This can usually be found in Program Files\Microsoft Office\Office''nn''\Samples\Northwind.mdb" (where ''nn'' signifies your version of Office). If you are unable to locate this database on your system it can be downloaded from [http://www.microsoft.com/downloads/details.aspx?FamilyID=C6661372-8DBE-422B-8676-C632D66C529C&displaylang=en Microsoft's web site].
 
The chapter assumes that you have Microsoft Access installed together with the "NorthWind" sample Access database. This can usually be found in Program Files\Microsoft Office\Office''nn''\Samples\Northwind.mdb" (where ''nn'' signifies your version of Office). If you are unable to locate this database on your system it can be downloaded from [http://www.microsoft.com/downloads/details.aspx?FamilyID=C6661372-8DBE-422B-8676-C632D66C529C&displaylang=en Microsoft's web site].
 +
 +
== Connected to a Database ==
 +
 +
Begin by launching Visual Studio and creating a new Windows Application project called "VBdatabase". Once the new project has been created the first task is to connect to the Northwind database. Click on the ''View'' menu and select ''Server Explorer''. The Server Explorer panel will appear on the left hand side of the main Visual Studio area:
 +
 +
[[Image:Exampl.jpg]]
 +
 +
This panel allows you to browse servers on your network and locate databases. Click on the ''Connect to Database'' button (highlighted above). The ''Add Connection'' dialog will appear as follows:
 +
 +
[[Image:Exampl.jpg]]
 +
 +
Click on the ''Browse'' button and locate the ''Northwind.mdb" database. Once you have selected the Northwind database click on the ''Test Connnection'' button to verify the database is accessible.

Revision as of 17:57, 9 August 2007

In this chapter of Visual Basic Essentials is intended to provide a detailed overview of developing applications that work with databases using Visual Basic and ADO.Net. As with most other aspects of Visual Basic and Visual Studio, Microsoft have put a significant amount of work into making it easy to work with databases. In fact, an incredible amount of database functionality can be built into a Visual Basic application without actually writing a single line of code.

The examples in this chapter work with a Microsoft Access database. The concepts covered, however, apply equally to other databases such as Microsoft SQL Server.

The chapter assumes that you have Microsoft Access installed together with the "NorthWind" sample Access database. This can usually be found in Program Files\Microsoft Office\Officenn\Samples\Northwind.mdb" (where nn signifies your version of Office). If you are unable to locate this database on your system it can be downloaded from Microsoft's web site.

Connected to a Database

Begin by launching Visual Studio and creating a new Windows Application project called "VBdatabase". Once the new project has been created the first task is to connect to the Northwind database. Click on the View menu and select Server Explorer. The Server Explorer panel will appear on the left hand side of the main Visual Studio area:

File:Exampl.jpg

This panel allows you to browse servers on your network and locate databases. Click on the Connect to Database button (highlighted above). The Add Connection dialog will appear as follows:

File:Exampl.jpg

Click on the Browse button and locate the Northwind.mdb" database. Once you have selected the Northwind database click on the Test Connnection button to verify the database is accessible.