回答
这段代码演示了如何从Visual Basic编写6.使用MySQL的ODBC驱动程序和Microsoft远程数据基于Windows的应用程序连接到MySQL数据库对象很容易从MySQL数据库服务器连接和检索记录。
■下载并安装MySQL ODBC驱动程序。
■设置一个MySQL用户名和密码组合,允许来自任何主机的连接。请参阅MySQL授予命令。
■启动一个新的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
远程数据对象已被微软宣布废弃。我会建议尝试使用ADO。 http://msdn.microsoft.com/en-us/library/ms810810.aspx#mdac_technologies_road_map_old_topic9 – MarkJ 2010-01-18 12:12:24
谷歌表示,你可以使用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的连接字符串从here。
警告:air code。我从来没有做过这件事。
我已经使用类似这样的代码,我可以证明它的工作原理。 – 2010-01-18 20:55:56
- 1. 从ASP.Net连接到mySQL数据库(vb)
- 2. MySQL - VB - 连接错误ReportViewer
- 3. Php - 将连接池连接到Mysql
- 4. 将C连接到mysql
- 5. 将nodejs连接到mysql
- 6. 将Canopy连接到mysql
- 7. 将Android连接到MySQL
- 8. 将MySQL连接到Dropbox
- 9. 将phpMyAdmin连接到MySQL Workbench
- 10. 将mysql连接到postgresql
- 11. 连接mysql数据库在vb
- 12. Webpart连接asp.net VB
- 13. VB和Oracle连接
- 14. 连接到SQL实例采用VB 6.0
- 15. 如何使用VB连接到TFS
- 16. 在VB中连接到Oracle数据库
- 17. VB 6连接到Web服务
- 18. Lua连接到MySQL
- 19. 连接php到mysql
- 20. C++连接到MySQL
- 21. 连接到MySQL,CSHTML
- 22. Android:连接到MySql
- 23. Vb.net连接到MySql
- 24. Spotfire连接到mysql?
- 25. 将外部mySql连接到Google App Engine
- 26. 将Mysql数据库连接到VirtualBox Vagrant?
- 27. 将PHP连接到MYSQL时mysqli_error()
- 28. 将MySQL数据库连接到php
- 29. 将VB.NET连接到MySQL数据库
- 30. 将android连接到mysql数据库
您可以使用ODBC或OleDB。为此,您需要适用于MySQL的驱动程序或ole db提供程序。 – shahkalpesh 2010-01-18 07:06:43