vb6.0如何打开access2003的数据库?
vb6.0如何打开access2003的数据库?
[解决办法]
我用的就是 2003,应该兼容 2000 版本。没有什么特别的。
如果,你使用ADO,创建连接字符串时选择 Provider=Microsoft.Jet.OLEDB.4.0。
如果使用DAO,选 工程-引用 菜单,选中 microsoft dao 3.6 object library,把 低于它版本的 DAO 库引用去掉。如果你使用DAO库对象,到这一步就可以了。
如果你使用data控件:
dim db as dao.database, rs as dao.recordset
set db = dbengine.opendatabase(app.path & "\yourDB.mdb ")
set rs = db.openrecordset( "select * from yourTable ") 'SQL语句根据你的需要写
set data1.recordset = rs
[解决办法]
用ADO吧
dim conn as new adodb.connection
dim rs as new adodb.recordset
with conn
if .State = adStateOpen Then .Close
.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\数据库名.mdb;Mode=ReadWrite;Persist Security Info=False "
.Open
end with
if rs.state=adstateopen then rs.close
rs.open "select * from 表名 ",conn,adopenkeyset,adlockreadonly
set mshflexgrid1.datasource=rs
rs.close
conn.close
[解决办法]
ADO 就是方便! 写个例子.......
Public rs As New ADODB.Recordset
Public Sub OpenConn()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\data\data.mdb;Jet OLEDB:Database Password=;Persist Security Info=False; "
End Sub
'关闭数据库连接
Public Sub CloseConn()
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub