VB如何打开MDB数据库中的一个表
3个回答
推荐于2018-04-05
展开全部
VB中打开数据库的方法有很多,给你一个用ADO打开数据库的方法:首先在“工程”中引用"Microsoft Activex Data Objects 2.8 Library"'安装Offices后就会有的。Dim DB As Connection
Dim rs As Recordset Private Sub Command1_Click()
Set DB = New ADODB.Connection
Set rs = New ADODB.Recordset
DB.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据库名.mdb;jet oledb:database password=123456"
DB.Open
rs.Open "select * from 表名", DB, adOpenStatic, adLockReadOnly
rs.Close注意:1.在“工程”中引用"Microsoft Activex Data Objects 2.8 Library" 2.代码写好后先保存,然把准备好的Access数据库放到代码保存的文件夹下。 3."select * from 表名",是打开数据库中叫做“表名”的一个表中全部数据。 可以用Msgbox rs.Fields(1).Value来调出表中的第一个值
Dim rs As Recordset Private Sub Command1_Click()
Set DB = New ADODB.Connection
Set rs = New ADODB.Recordset
DB.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据库名.mdb;jet oledb:database password=123456"
DB.Open
rs.Open "select * from 表名", DB, adOpenStatic, adLockReadOnly
rs.Close注意:1.在“工程”中引用"Microsoft Activex Data Objects 2.8 Library" 2.代码写好后先保存,然把准备好的Access数据库放到代码保存的文件夹下。 3."select * from 表名",是打开数据库中叫做“表名”的一个表中全部数据。 可以用Msgbox rs.Fields(1).Value来调出表中的第一个值
2013-10-19
展开全部
给这段代码你好好研究一下Public Function ExecuteSQL(ByVal sql As String, MsgString As String, HasError As Boolean) As ADODB.Recordset
Dim rst As ADODB.Recordset Dim sTokens() As String
On Error GoTo ExcuteSQL_Error
sTokens = Split(sql)
If InStr("INSERT,DELETE,UPDATE", UCase(sTokens(0))) Then
cnn.Execute sql
MsgString = sTokens(0) & "query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
HasError = False
Exit FunctionExcuteSQL_Error:
MsgString = "查询错误:" & Err.Description
Set rst = Nothing
HasError = TrueEnd Function
Dim rst As ADODB.Recordset Dim sTokens() As String
On Error GoTo ExcuteSQL_Error
sTokens = Split(sql)
If InStr("INSERT,DELETE,UPDATE", UCase(sTokens(0))) Then
cnn.Execute sql
MsgString = sTokens(0) & "query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
HasError = False
Exit FunctionExcuteSQL_Error:
MsgString = "查询错误:" & Err.Description
Set rst = Nothing
HasError = TrueEnd Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-19
展开全部
set myfolder=myfso.getfolder("****")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询