Ask the Expert

Integrating and operating VB with MySQL

I am working on a project, building an application in VB, and MySQL is its database. Can you offer any tips on finding and using the code to connect VB to the MySQL database? Can VB apps and MySQL work together well? Also, how do I call the record set and add, delete and update in VB to the MySQL database?

    Requires Free Membership to View

MySQL and VB work well together, using MySQL Connector/ODBC for VB6 and Connector/NET for VB.NET. The connectors are available for download.

As for tip and tutorials, I will shamelessly plug a site I started back in 2003 called www.vbmysql.com. At the site you can find a good-sized archive of sample code and a series of articles regarding using Visual Basic and MySQL together.

Here's a basic example of inserting data using VB6 with MYSQL from the site's sample code collection:

 Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection
 
 Dim rs As ADODB.Recordset
 Set rs = New ADODB.Recordset

 conn.CursorLocation = adUseClient
 conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
       & "SERVER=127.0.0.1;" _
       & "DATABASE=test;" _
       & "UID=testuser;" _
       & "PWD=12345;" _
       & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384

 conn.Open

 rs.Open "SELECT * FROM mytable WHERE 1=0", conn, adOpenStatic, adLockOptimistic
 rs.AddNew

 rs!Name = "Johnny Bravo"
 rs!address = "Mama's House"
 rs.Update

 txtID.Text = rs!person_id
 
 rs.Close
 Set rs = Nothing
 conn.Close
 Set conn = Nothing

This was first published in September 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: