liushu-p 发表于 2006-6-9 08:44:00

关于数据库联结问题

<P>在VBA中用下列语句连结数据库</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set conn = New ADODB.Connection<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.CursorLocation = adUseClient<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Provider = "Microsoft.Jet.OLEDB.4.0;"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connstr = "Data Surce=d:\制图\数据库\塔巴庙探井.mdb;"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open connstr</P>
<P>但运行时出现错误如下:</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; Compile error:</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; Can't find project or library</P>
<P>我引用的是Microsoft ActiveX Data Objects 2.5&nbsp;&nbsp;library</P>
<P>请问如何解决?非常感谢!</P>

persist 发表于 2006-6-30 18:33:00

<P>菜单 工具 -〉引用-〉Micorsoft Access 11.0 Objects&nbsp;&nbsp;library 试试</P>
<P>Set Public conn As New ADODB.Connection&nbsp;&nbsp; '定义新连接<BR>Public cmd As New ADODB.Command&nbsp;&nbsp;&nbsp;&nbsp; '定义指令<BR>Public rs As New ADODB.Recordset&nbsp; '定义两个记录集</P>
<P>set conn = New Connection<BR>conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\制图\数据库\塔巴庙探井.mdb"<BR>Set cmd.ActiveConnection = conn<BR>cmd.CommandText = "select * from 表名"</P>
<P>rs.CursorLocation = adUseClient</P>
<P>rs.Open cmd, , adOpenStatic, adLockBatchOptimistic</P>
页: [1]
查看完整版本: 关于数据库联结问题