VB6 连接MySql数据库
时间:2021-07-01 10:21:17
帮助过:4人阅读
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
VB6 连接MySql数据库
标签: