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

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


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


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.


Interactive Database Browser
Try browsing customer records using the navigation buttons:
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.

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

Visual Basic 6 Made Easy
The ultimate beginner-friendly guide for mastering Windows-based application development using Visual Basic 6. Used as a textbook by universities worldwide.
What You'll Learn:
- Comprehensive coverage of VB6 coding techniques
- Database application development
- Practical examples and projects
- Debugging and error handling
- Advanced database integration
- Professional UI development

Visual Basic 2022 Made Easy
The ultimate guide to VB.NET programming in Visual Studio 2022. Master modern VB development with this comprehensive resource.
What You'll Learn:
- Modern VB.NET coding techniques
- Visual Studio 2022 features
- Database programming with ADO.NET
- Advanced UI development
- Entity Framework integration
- Deployment strategies