Lesson 23: Creating a Database Application in VB6

Learn to connect to databases, browse records, and create professional database interfaces

Key Takeaway

Visual Basic provides powerful database capabilities through the Data Control, allowing you to create professional database applications without complex coding.

Welcome to Lesson 23 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to create database applications using VB6's built-in Data Control. We'll connect to the NWIND.MDB sample database, browse customer records, and create a professional database interface.

23.1 Creating Simple Database Application

Visual Basic provides the capability to effectively manage databases created with various database programs, including MS Access, Oracle, MySQL, and more. In this lesson, our focus is not on database file creation, but rather on accessing database files within the VB environment.

Database Connectivity

Connect to Access, SQL Server, Oracle, and other databases

Record Navigation

Browse through records with intuitive navigation controls

Professional UI

Create clean, professional database interfaces

23.1.1 Required Components

To create a database browser application, we need these essential components:

1Data Control

The core component for database connectivity

2Database File

NWIND.MDB sample database included with VB6

3Labels

To display field names and data values

4Binding

Connecting controls to database fields

Data Control in Toolbox
Figure 23.1: The Data Control in VB6 Toolbox

23.2 Connecting Data Control to Database

To connect the data control to a database, we need to configure its properties:

1DatabaseName Property

Specify the path to NWIND.MDB database file

2RecordSource Property

Select the Customers table from the database

3Control Binding

Connect labels to specific fields in the table

Setting DatabaseName Property
Figure 23.2: Setting the DatabaseName Property
Selecting NWIND.MDB
Figure 23.3: Selecting the NWIND.MDB Database

23.2.1 Property Configuration

The next step is to double-click on the RecordSource property to select the customers table from the database file NWIND.MDB, as shown in Figure 23.4. You can also change the caption of the data control to anything. After that, we will place a label and change its caption to Customer Name. In addition, insert another label and name it as cus_name and leave the label empty as customers' names will appear here when we click the arrows on the data control.

DataSource Property

Set to the Data Control name (data_navigator)

DataField Property

Set to the specific field (ContactName)

RecordSource

Set to the Customers table

Setting RecordSource Property
Figure 23.4: Setting the RecordSource Property
Setting DataField Property
Figure 23.5: Setting the DataField Property

23.3 Running the Application

Now, press F5 and run the program. You should be able to browse all the customers' names by clicking the arrows on the data control, as shown in Figure 23.7.

Database Application Design
Figure 23.6: The Design Interface
Runtime Interface
Figure 23.7: The Runtime Interface

Interactive Database Browser

Try browsing customer records using the navigation buttons:

Customer Name: Maria Anders
Company: Alfreds Futterkiste
City: Berlin
Record 1 of 91

23.4 Creating Professional Interfaces

You can add other fields using exactly the same method. For example, you can add title, company, address, City, postcode, telephone number and more to the database browser. Besides, you can design a more professional interface, as shown in Figure 23.8.

Professional Database Interface
Figure 23.8: Professional Database Interface

Lesson Summary

In this lesson, you've learned how to create a database application in VB6:

Data Control Setup

Configuring DatabaseName and RecordSource properties

Control Binding

Connecting labels to database fields

Record Navigation

Browsing records with the Data Control

Professional UI

Creating clean database interfaces

Important Note

The NWIND.MDB database file is typically located in the Microsoft Visual Studio\VB98\ directory. If you can't find it, you may need to install the sample databases that come with VB6.

Practice Exercises

Enhance your database application with these exercises:

Exercise 1: Add More Fields

Display additional customer information like address, city, and phone number.

Exercise 2: Search Functionality

Implement a search box to find customers by name.

Exercise 3: Multiple Tables

Connect to the Orders table and display order history.

Exercise 4: Data Grid

Use the DataGrid control to show multiple records at once.

Exercise 5: Edit Records

Add functionality to edit and update customer information.

Next Lesson

Continue your VB6 journey with Lesson 24: Advanced Database Techniques.

Related Resources

Full VB6 Tutorial Index

Complete list of all VB6 lessons with descriptions

Explore Tutorials

Visual Basic Examples

Practical VB6 code samples for real-world applications

View Examples

Multimedia Player

Learn to create a media player in VB6

Previous Lesson

Advanced Database

Learn advanced database techniques

Next Lesson