发布网友 发布时间:2022-05-10 19:46
共3个回答
热心网友 时间:2023-10-25 19:26
最好的办法就是装一个版本很高的OFFICE,并包含Access。或者从网上直接下载 ado 2.8的安装包。在微软的网站上就有,免费的组件。热心网友 时间:2023-10-25 19:26
1、装一个版本很高的OFFICE,并包含Access;热心网友 时间:2023-10-25 19:27
由于ADO对象不直接支持MySQL,所以必须先安装MyODBC, 后者也是一个免费产品,在 www.mysql.org上有下载,安装好了MyODBC, 就可以在ODBC数据源管理中配置一个数据源名称,把它指向你想连接的MySQL数据库。代码如下:Sub connectMySQL() '通过MyODBC去连接MySQL数据库,并将Microsoft SQL Server 7 '的数据转进mysql中 Dim sConnect As String, sSql As String, i As Long Dim cnMSSQL As New ADODB.Connection Dim cnMySQL As New ADODB.Connection '声明并创建对象 连接 Dim rs As New ADODB.Recordset '声明并创建对象 记录集 Dim cm As New ADODB.Command '声明并创建对象 命令 sConnect = "dsn=mysql1" '指定MySQL的数据源名称 cnMySQL.Open sConnect '连接到 mysql sConnect="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=123456;Initial Catalog=softdown;Data Source=ntserver" '连接到 ms sql server 7 cnMSSQL.Open sConnect 'sSql = "create table softinfo (softNum smallint,softname varchar(70),softdesc blob," & _ "softpath varchar(30),softleng varchar(10),softclass varchar(10),softsugest tinyint(1)," & _ "softdown smallint(4))" '创建新的MySQL数据表语句 sSql = "select * from softinfo order by softnum" rs.Open sSql, cnMSSQL, 1, 1 While Not rs.EOF sSql = "insert into softinfo values (" & Trim(rs(0).Value) & ",'" & Trim(rs(1).Value) & _ "','" & Trim(rs(2).Value) & "','" & Trim(rs(3).Value) & "','" & Trim(rs(4).Value) & _ "','" & Trim(rs(5).Value) & "'," & Trim(rs(6).Value) & "," & Trim(rs(7).Value) & ")" cm.ActiveConnection = cnMySQL cm.CommandType = adCmdText cm.CommandText = sSql cm.Execute rs.MoveNext Wend rs.Close Set rs = Nothing cnMySQL.Close Set cnMySQL = Nothing cnMSSQL.Close Set cnMSSQL = Nothing End Sub