How to connect VB6 to Mysql

To connect a vb6 project to mysql DataBase you need to install MySQL Connector/ODBC 5.1 on your Machine.

You can download MySQL Connector/ODBC 5.1 from link.

After download and installing the MySql connector observe following steps to accomplish your task.

Declare ADODB connection:

 1: Dim ConnMySql As New ADODB.Connection

Declare ADODB Recordset

 1: Dim RsMySql As New ADODB.Recordset

Declare ADODB Command

 1: Dim CmdMySql As New ADODB.Command

After declaration you have to open a connection which can be done as follows:

 1: ConnMySql.Open "Driver={MySQL ODBC 5.1 Driver};Server=your host server name or IP address;Database=your data base name; User=your user name;Password=your password;Option=3;"
1:CmdMySql.CommandText = "select * from Table"
 2: RsMySql.Open CmdMxRcrdMySql.CommandText, ConnMySql

Make sure after finishing your operation with the data base you close your connection and recordset.

Following is  how you can close your recordset and connection.

 1: RsMySql.Close
 1: ConnMySql.Close

If  there is any question about above procedure please ask through comments.

Tagged: ,
  • http://www.zen-cart.com/forum/showthread.php?t=169015 Antone Jeppsen

    Many thanks for this information. Powder coating is the organization I am in and I am generally in search of new ways to enhance.

  • http://www.mojegume.si/dunlop gume dunlop

    letne gume dunlop
    Visit out my website that I just finished recently.

  • http://www.horseracegames.com Horse Games

    Great wordpress blog here.. It’s hard to find quality writing like yours these days. I really appreciate people like you! take care :)

  • http://www.bise.pl/ranking-polskich-bankow/ ranking banków

    I want your help. I like your blog. Your words are interesting. I got here by mistake and I started reading. I became interested in the topic and I am thinking whether I could use your texts on my blog, of course with the quotation. Please answer, thanks very much.

  • Syed Asad Ahmed

    @ranking banków: Thanks for the word. Please go ahead with it, just don’t forget to link back my post which you’re referring to.

  • http://geekcent.com/seedbox-hosting linux themes

    I like this site so much, saved to my bookmarks .

  • http://www.tudou.com/ tudou99

    Youre so cool! I dont suppose Ive read anything in this way prior to. So nice to seek out somebody by incorporating original ideas on this subject. realy thank you for beginning this up. this web site could be something that is required on the net, an individual following some originality. useful purpose of bringing some thing new to your web!

  • Peter V.

    I could not get this to work. I had to “set” the variables after “dimming” them before it worked. Any ideas why?
       
        Dim connMySQL As ADODB.Connection    Dim RsMySQL As ADODB.Recordset    Dim cmdMySQL As ADODB.Command    Set connMySQL = New Connection    Set RsMySQL = New Recordset    Set cmdMySQL = New Command
    also, the
    RsMySql.Open CmdMxRcrdMySql.CommandText, ConnMySql
    should be:
    RsMySQL.Open cmdMySQL.CommandText, connMySQL

    Thanks for putting me on the correect road.
    greets, Peter.

  • Yasirbacker

    Thanks for giving such information

  • http://www.facebook.com/syedhassan01 Faizan Ul Hassan

    tnkx alot

  • buzz4rd

    I always get it. How can I solve it ? plz

  • Roshan

    Is there any need to set reference for this code to work out??? Please reply…