Putting Your MySQL Data into Datagrid with ADODC

I believe the following information I post here is not too easy to be found while you are searching in internet. I’ve been wasted for almost 2 days to making VB6’s Datagrid control get connected to some of MySQL database. Some of this information are also taken from some books I read. I’m sure some of the other beginner like me would face this problem also, so I feel this is important to share with all of you.

So, let’s begin. When you try to connect your Datagrid control (from Microsoft Datagrid 6.0 (OLEDB)), please make sure you have already put ADODC to your project reference. If don’t, you can add some ADODC control at your form, then run the project for the first time (later on you can delete this ADODC control; it’s only for initial running to make the ADODC’s reference be included with your program).

Please note, you need to install MySQL ODBC connector, but please make sure you don’t use the version 3.51, because ADODC 6.0 cannot run with this version. Please install the version 5.1 or newer. For you who dont’ have and install it (the MySQL ODBC Connector), you can get it from the following link : http://dev.mysql.com/downloads/connector/odbc/5.1.html

Now, let’s start our VB6. In coding windows, please type the following codes :

Option Explicit
Dim con As ADODB.Connection
Dim tbITSupport As ADODB.Recordset
Private Sub Form_Load()
    Set con = New ADODB.Connection
    con.CursorLocation = adUseClient
    con.ConnectionString = “Driver={MySQL ODBC 5.1 Driver};” & _
                        “SERVER=;PWD=;UID=;” & _
    Set tbITSupport = New ADODB.Recordset
    tbITSupport.LockType = adLockOptimistic
    tbITSupport.CursorType = adOpenDynamic
    tbITSupport.Open “Select noform,tgl,jam,departemen,extension from itsupport”, _
                    con, , , adCmdText
    Set DataGrid1.DataSource = tbITSupport
End Sub


Note : I took some columns from my project (my table name in MySQL is ITSupport).

Any comment or want to add some information to help me sharing the topic more completely? So, please drop your comment. I would really appreciate it. Thank you all.


9 Responses

  1. morning sir,
    i already made form like that but data didn’t appear in datagrid. Can you help me.

  2. Short but sweet description.Exact code by gilbertusg, thank’s.

  3. I have a error msg on ODB 5.1
    [Microsoft][ODBC Driver Mangager]Data Source name not found and no default driver specified
    i am running windows home premuim 64bit

  4. Dear Sir,

    I have spent almost four hours searching for this. Thank you very much. It is now working fine.

    I am able to connect to Datagrid with MySQL Database using VB.


    Augustin Codjo HOUDE
    CEO – Missionsoft Industrial Solutions

  5. I have a error msg
    [Microsoft][ODBC Driver Mangager]Data Source name not found and no default driver specified
    i am running windows 7 home basic
    i have installed ODBC 5.1 Driver

    • Hi Rikin,

      You can try to create ODBC (go to administrative tool) to connect your mySQL database. Normally when you create ODBC for mySQL, you have to be able to select driver of MySQL ODBC 5.1 Driver. If you cannot find this driver, it means your ODBC connector to mySQL has been failed. Please check this driver first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: