VB连接到MySQL(Connecting VB to MySQL)

2019-11-02 18:37发布

我想问一下如何VB6连接到MySQL一些帮助? 请提供参考为好。

非常感谢

Answer 1:

谷歌表示,你可以使用ADO和MySQL的ODBC驱动程序。

Dim strConnection$, conn As Connection 

'Fill in the placeholders with your server details'
strConnection = "Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;" & _ 
   "Database=myDataBase;User=myUsername;Password=myPassword;Option=3"

Set conn = New Connection  
conn.Open strConnection

从MySQL的ODBC连接字符串在这里 。

警告: 空气代码 。 我从来没有这个工作我自己。



Answer 2:

链接: http://paulbradley.tv/37/

这段代码演示了如何连接到从Visual Basic编写6.使用MySQL的ODBC驱动程序和Microsoft远程数据对象是很容易的连接和检索记录从MySQL数据库服务器的基于Windows的应用程序中的MySQL数据库。

■下载并安装MySQL的ODBC驱动程序。

■建立一个MySQL的用户名和密码组合,将允许从任何主机连接。 见MySQLs授予命令。

■启动一个新的Visual Basic项目,并添加Microsoft远程数据对象 - 使用菜单选择Project | 引用,然后从列表中选择Microsoft远程数据对象。

示例代码

Private Sub cmdConnectMySQL_Click()

Dim cnMySql As New rdoConnection
Dim rdoQry  As New rdoQuery
Dim rdoRS   As rdoResultset

' set up a remote data connection
' using the MySQL ODBC driver.
' change the connect string with your username,
' password, server name and the database you
' wish to connect to.

cnMySql.CursorDriver = rdUseOdbc
cnMySql.Connect = "uid=YourUserName;pwd=YourPassword;
    server=YourServerName;" & _
    "driver={MySQL ODBC 3.51 Driver};
    database=YourDataBase;dsn=;"
cnMySql.EstablishConnection

' set up a remote data object query
' specifying the SQL statement to run.

With rdoQry
    .Name = "selectUsers"
    .SQL = "select * from user"
    .RowsetSize = 1
    Set .ActiveConnection = cnMySql
    Set rdoRS = .OpenResultset(
            rdOpenKeyset, rdConcurRowVer)
End With

' loop through the record set
' processing the records and fields.

Do Until rdoRS.EOF
    With rdoRS

    ' your code to process the fields
    ' to access a field called username you would
    ' reference it like !username

        rdoRS.MoveNext
    End With
Loop

' close record set
' close connection to the database

rdoRS.Close
cnMySql.Close

End Sub


文章来源: Connecting VB to MySQL
标签: mysql vb6