目测 VB6 的资料比较少了,花了好久时间写了个查询语句
首先下载驱动程序,我是win7 x64 不知道刚开始下载了一个5.1 x64的驱动为什么连接不上,总提示找不到驱动,下载5.3 32位后正常
http://dev.mysql.com/downloads/connector/odbc/
Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset ' 定义数据库连接字符串变量 Dim strCn As String ' 定义数据库连接参数变量 Dim db_host As String Dim db_user As String Dim db_pass As String Dim db_data As String Dim cmd As New ADODB.Command ' 定义 SQL 语句变量 Dim sql As String ' 初始化数据库连接变量 db_host = "127.0.0.1" db_user = "root" db_pass = "" db_data = "family" strCn = "DRIVER={MySQL ODBC 5.3 Unicode Driver};" & _ "SERVER=" & db_host & ";" & _ "DATABASE=" & db_data & ";" & _ "UID=" & db_user & ";PWD=" & db_pass & ";" & _ "OPTION=3;stmt=SET NAMES UTF8" ' 连接数据库 'cn.Open strCn ' 设置该属性, 使 recordcount 和 absolutepage 属性可用 'cn.CursorLocation = adUseClient 'rs.Open "tb_sys_emp", cn, adOpenKeyset, adLockOptimistic 'rs.MoveFirst 'Do While rs.EOF = False ' Debug.Print rs.Fields("emp_name") ' rs.MoveNext 'Loop 'rs.Close cn.Open strCn Set cmd.ActiveConnection = cn cmd.CommandText = "select emp_name from tb_sys_emp" cmd.CommandType = adCmdText cmd.CommandTimeout = 15 Set rs = cmd.Execute rs.MoveFirst Do While rs.EOF = False Debug.Print rs.Fields("emp_name") rs.MoveNext Loop rs.Close Debug.Print list.Count