Results 1 to 6 of 6

Thread: MySQL to VB

  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Unanswered: MySQL to VB

    Im having trouble linking a MySQL database to Visual Basic. can anyone give me any pointers?

    Cheers

  2. #2
    Join Date
    Jul 2001
    Location
    NC
    Posts
    102
    More information, please
    1) can you connect to your data using a mySQL tool (eg mySQLFront)?
    2) what version of mySQL are you using and which database (eg INNODB)?
    3) do you have the appropriate rights?
    4) what drivers are you using (eg myODBC)?
    5) what VB are you using (vb4, vb5, vb6, .net)? Are you using ADO or DAO? What is your connection string?

  3. #3
    Join Date
    Apr 2004
    Posts
    110
    Greetings everybody

    I`m experiecing a similar problem. The following list details the tools and versions I`m using to connect to a MYSQL database :

    1) Visual Basic 6.
    2) Connecting via ADO.
    3) myODBC 3.51.8 win drivers. MySQL is running on a Windows XP machine.
    4) I can connect via an ADO control.
    5) The MySQL database is in the InnoDB format.

    I have no starting clue as to how to programmatically create the connection string. Can anyone point me in the right direction?

    thx, in advance

    George Papadopoulos

  4. #4
    Join Date
    Jul 2004
    Posts
    69
    Private Sub cmdConnect_Click()
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset

    'connect to MySQL server using MySQL ODBC 3.51 Driver
    Set conn = New ADODB.Connection
    conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};"_
    & "SERVER=localhost;"_
    & " DATABASE=test;"_
    & "UID=yourUserID;PWD=yourPassword"

    conn.Open
    End Sub

    OR you can create a User DSN for your connection (im sure you know how to create one...)

    Private Sub cmdConnect_Click()
    Dim conn As New ADODB.Connection
    Dim rs As New Recordset
    Dim tmpstr As String

    conn.Open "DSN=YourDSN"
    tmpstr = "SELECT * from user"
    rs.Source = mySQL
    Set rs.ActiveConnection = conn
    rs.CursorLocation = adUseClient
    rs.Open

    End Sub

    Be sure you installed MyODBC drivers...
    Last edited by Daniel_Johns; 08-31-04 at 10:25.

  5. #5
    Join Date
    Apr 2004
    Posts
    110
    Very nice! The code seems to work. I used the first code snippet and thus created no DSN.
    I would like to ask if you know of any URL`s with more detailed info on connecting and accessing databases using ADO?

    thx, in advance

    George Papadopoulos

  6. #6
    Join Date
    Jul 2004
    Posts
    69
    Hi! I dont really have an exact URL that I can recommend. All I do is that go to some discussion boards such as this. In this way, you can have all the help with a lot of guys who willingy try to help others hanging around here. Just try posting here and dbforums guys will try to answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •