[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-odbc
Subject:    Re: Visual Basic and MyODBC
From:       "Jonathan D. Hoover" <jon.hoover () hooverco ! com>
Date:       2000-09-23 14:23:21
[Download RAW message or body]

Ah, finally one I can answer with my eyes closed (its all I have been doing
all week)...
First, make sure you have "Project Menu -> References" set. You want
Microsoft ActiveX Data Objects 2.5 Library and the RecordSet library
selected. Also, don't use "Connection" and "Recordset" by themselves. Make
sure to prepend the ADODB. to them. ADODB is better supported and is the
newer technology. Also, don't use "Workspaces". Oh, and the following will
work WITHOUT a DSN which makes it really nice when you go to send off the
program to a user. You don't have to explain how to create a DSN. Better
yet, a program like InstallShield will even make all the registry entries
you need for installing the MyODBC driver as well.

Here's some sample code for opening and manipulating data in VB 6. If you
have any questions, let me know.

    Dim ODBCConnStr As String
    Dim Conn1 As ADODB.Connection
    Dim Cmd1 As ADODB.Command
    Dim Rs1 As ADODB.Recordset
    ODBCConnStr =
"DRIVER={MySQL};SERVER=servername.yourdomain.com;DATABASE=databaseyoumade;UI
D=yourid;PWD=yourpass"

    Set Conn1 = New ADODB.Connection
    Conn1.ConnectionString = ODBCConnStr
    Conn1.Open

    Set Cmd1 = New ADODB.Command
    Cmd1.ActiveConnection = Conn1
    Cmd1.CommandText = "SELECT * FROM adminusers WHERE email='" &
txtAdminEmail.Text & "' AND " & _
        "password='" & txtAdminPassword.Text & "'"
    Set Rs1 = Cmd1.Execute()

    If Rs1.EOF = False Then
        Do something...
            Dim strAlertsInsert As String

        strAlertsInsert = "INSERT INTO alerts VALUES (" & _
            "\N," & _
            "Hello," & _
            "'" & lstUser.List(x) & "','" & _
            txtURL & "')"


        Dim Cmd2 As ADODB.Command
        Set Cmd2 = New ADODB.Command
        Cmd2.ActiveConnection = Conn1
        Dim Rs2 As ADODB.Recordset
        Cmd2.CommandText = strAlertsInsert
        Set Rs2 = Cmd2.Execute() `Note, this executes strAlertsInsert -
which inserts data into MySQL.
  End If


----- Original Message -----
From: "Mickael GALLARD" <mlgd@wanadoo.fr>
To: <myodbc@lists.mysql.com>
Sent: Saturday, September 23, 2000 8:30 AM
Subject: Visual Basic and MyODBC


Hello

How to use a MySQL database with Visual Basic?

When i use commands :

Dim wBase As Database
Dim wRecordset As Recordset
Set wBase = OpenDatabase("", 0, 0, "ODBC;DSN=Mysql;UID=root;DATABASE=test")
Set wRecordset = wBase.OpenRecordset("select * from tabletest")
wBase.Close

the driver return error 3146

Thanks



---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail myodbc-thread2136@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail myodbc-unsubscribe@lists.mysql.com instead.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic