Program a Visual Basic MySQL Database
By Stephen Bucaro
MySQL is a powerful relational database management system used by many major organizations such
as Yahoo, NASA and the U.S. Census Bureau. The best thing about MySQL is that it is open source
software available free of charge for non-commercial use under the open source GNU public License.
In my previous article "A Free Windows Graphical Interface to MySQL" we used MySQLGUI for executing
SQL queries on our example database. While MySQLGUI is a great tool for learning SQL and performing
database administration tasks, it is not an application that you would provide to the average user.
In this article I show you how to program a simple MySQL database browser using Visual Basic.
I assume that you already know how to program a simple Visual Basic .EXE project. By the way,
Janus Software provides a free application
for Windows and Linux that is very similar to Visual Basic.
In this example we will use Microsoft's ActiveX Data Object with a MySQL ODBC driver. The first
thing to do is download a MySQL ODBC driver from:
Oracle MySQL
On that Web page click on the link for "MyODBC 2.50 -- stable release". This takes you to the
download page for a Windows 95/98/Me driver, a Windows NT/2000/XP driver, and a Linux driver.
For my Windows 98 system, I downloaded myodbc-2.50.39-win95.zip and expanded it into a new subfolder
under the C:\mysql folder. To install a driver on Windows you must "register" it. Basically you create
an entry in the Windows Registry. These drivers come with a setup program that does the registration for you.
Start Visual Basic and create a new Standard .EXE Project. In Project References, set the checkbox
next to [x] Microsoft ActiveX Data Objects 2.0 Library.
This example presents the minimal code required to make a simple database browser, in fact, as you
can see, I didn't even put labels for the text boxes. I'm sure that starting with this bare-bones code,
you can program a much nicer looking application with more features.
This program will be designed specifically to browse the database created in the previous article
(firstdb). It contains one table named address with four fields named; name, address, city, and state.
Layout the form with three command buttons and four text boxes as shown below.
|