Database

You will create a simple Database application using the Database features available in .NET to link with an Access Database File.

Printer Friendly Download Tutorial (179KB) Download Source Code (36.8KB) Download Database File (152KB)

Step 1

Start Microsoft Visual Basic 2008 Express Edition, then select File then New Project... Choose Windows Forms Application from the New Project Window, enter a name for the Project and then click OK, see below:

New Project

Step 2

A Blank Form named Form1 should then appear, see below:

Form1

Step 3

With Form1 selected goto the Properties box and change the Name from Form1 to frmMain

Form1 Properties

Step 4

Then select "Data" then "Add New Data Source..." from the Menu and Choose "Database" if it is not already selected, see below:

Data Source Wizard

Step 5

Then on the "Choose Your Data Connection" page of the "Data Source Configuration Wizard" select "New Connection...", then set the "Data Source" by clicking "Change..." and then select the "Microsoft Access Database File" option, see below:

Change Data Source

Step 6

Select OK to set this option then the "Add Connection" screen will be displayed, click "Browse..." and then find the Folder containing the "Database File" on your Computer, downloaded from the webpage containing this tutorial, once selected the screen should show similar to below:

Add Connection

Step 7

Select OK to set the Connection, then from the "Choose Your Data Connection" wizard, select Next and then select Yes for including the Database in the Project if the Database was saved elsewhere, the wizard should show the "Save the Connection String to the Application Configuration File" page, see below:

Save the Connection String to the Application Configuration File

Step 8

Select Next on the Wizard, then on the "Choose Your Database Object", select the Checkbox next to "Tables", see below:

Choose Your Database Object

Step 9

Select Finish on the Wizard, if all the previous steps were followed the "Solution Explorer" should contain the below items:

Solution Explorer

Step 10

In the "Solution Explorer" select the "Data Sources" tab, this will show the "Music" table included in the Wizard, plus the Fields "ID", "Album", "Artist" and "Genre", see below:

Solution Explorer

Step 11

Select "ID" from the "Data Sources" tab on "Solution Explorer", then drag and drop onto the Form, which is keeping clicked on the ID then moveto drag until over the form then release to drop onto the Form, the Form will look as below:

frmMain with Database Field

Step 12

The "ID" Label and Textbox on the Form can be moved by clicking on it and moving it about the Form, select the "Album" item from "Solution Explorer" and drag and drop that onto the form, repeat this for the "Artist" and "Genre" fields, the Form should then look as below:

frmMain with Database Fields

Step 13

Save the Project as you have now finished the application, then click on Start:

Start

When you do the following will appear:

Application Running

Step 14

Just select the "Add" button - looks like a plus-sign then Enter some information in the Album, Artist and Genre Boxes, see below:

Database

Step 15

Click on the Close button Close on the top right to end the application.

This is a very simple example of how to create a Database-aware application using the Database features of Visual Basic 2008 - however it does have a problem it does not work with 64bit operating systems at all, this is why the tutorial has been delayed however there is not a solution except to use SQL Server Express. You can try and have a look at the Database options available as well as using a different Database File - even make it use another Database Provider such as SQL Server and make it your own!

Share

Copyright Comentsys © 1997 - 2009, All rights reserved. About | Contact | Link to Page
Valid XHTML 1.1! Valid CSS Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0 This website is ICRA rated