Option Explicit
'需要安装 MysqL 的 ODBC 驱动,官网上有,我的是 Connector ODBC 5.1
'先引用 Microsoft ActiveX Data Objects 6.0 Library 我的是 6.0,用最新的就行
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
Public fld As ADODB.Field
Public Sub connOpen()
End Sub
Public Sub connClose()
End Sub
'常用语句 'conn.Execute "drop database db_vb" 'conn.Execute "create database db_vb" 'conn.Execute "use db_vb" 'conn.Execute "create table test (id int primary key,name char(8) not null)" 'conn.Execute "insert into test value (1,'abc')" 'conn.Execute "insert into test value (2,'xyz')" '执行查询 'rs.Open "select * from test",conn '读取数据集 'Debug.Print rs.RecordCount '数据集数量 'rs.MoveFirst 'For Each fld In rs.Fields 'Debug.Print fld.Name,'列标题 'Next 'Debug.Print 'Do Until rs.EOF 'For Each fld In rs.Fields 'Debug.Print fld.Value,'Next 'rs.MoveNext 'Debug.Print 'Loop
原文链接:https://www.f2er.com/vb/257207.html