在VB中用ADO连Access数据库的代码怎么写?

zmingxia 2003-08-21 12:51:23
在VB中用ADO连Access数据库的代码怎么写?
...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2003-08-21
  • 打赏
  • 举报
回复
dim N as long
Dim strSQL As String

dim conn as New ADODB.Connection
dim rs as New ADODB.Recordset

strSQL = App.Path & "\Biblio.mdb"
strSQL = Replace(strSQL, "\\", "\")

With conn
If .State = adStateOpen Then
.Close
End If
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & strSQL
.Open
End With

With rs
.Open "Select * from Authors;", conn, adOpenStatic, adLockOptimistic
If .BOF And .EOF Then
msgbox "没有任何记录"
Exit Sub
End If
.MoveFirst
.movelast
msgbox "有" & .recordcount & "条记录!"
N = .recordcount
End With
iiboy 2003-08-21
  • 打赏
  • 举报
回复
dim conn as ADODB.Connection
dim rs as ADODB.Recordset
set conn = new adodb.connection
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBasePath\DATABASEName.mdb;Persist Security Info=False"
set rs=new adodb.recordset
rs.open "Select * from 表名",conn,adOpenDynamic,adLockOptimistic
qingming81 2003-08-21
  • 打赏
  • 举报
回复
dim N as long
Dim strSQL As String

dim conn as New ADODB.Connection
dim rs as New ADODB.Recordset

strSQL = App.Path & "\Biblio.mdb"
strSQL = Replace(strSQL, "\\", "\")

With conn
If .State = adStateOpen Then
.Close
End If
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & strSQL
.Open
End With

With rs
.Open "Select * from Authors;", conn, adOpenStatic, adLockOptimistic
If .BOF And .EOF Then
msgbox "没有任何记录"
Exit Sub
End If
.MoveFirst
.movelast
msgbox "有" & .recordcount & "条记录!"
N = .recordcount
End With
射天狼 2003-08-21
  • 打赏
  • 举报
回复
在菜单"工程/引用/Microsoft ActiveX Data Object 2.x(版本号)"

Dim CN As New ADODB.Connection
Dim Rs As New ADODB.Recordset


cn.ConnectionString = "DBQ=" & App.Path & "\TelePhone.mdb;DefaultDir=" & _
App.Path & ";Driver={Microsoft Access Driver (*.mdb)};UID=ADMIN;PWD=admind1234;"
cn.Open
lihonggen0 2003-08-21
  • 打赏
  • 举报
回复
工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)

Dim CN As New ADODB.Connection '定义数据库的连接
Dim Rs As New ADODB.Recordset

CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\NWIND.MDB;Persist Security Info=False"
CN.Open

Rs.CursorLocation = adUseClient
Rs.Open "select * from employees", CN, adOpenDynamic, adLockBatchOptimistic

Set DataGrid1.DataSource = Rs

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧