如何通过ADO,获取一个数据库文件里面所有的表
答案:2 悬赏:0 手机版
解决时间 2021-01-29 22:56
- 提问者网友:溺爱和你
- 2021-01-29 01:23
如何通过ADO,获取一个数据库文件里面所有的表
最佳答案
- 五星知识达人网友:老鼠爱大米
- 2021-01-29 02:25
试代码:
Private Sub Command1_Click()
Dim ADOrs As New Recordset
Dim ADOcn As New ADODB.Connection
Dim Yourt As New ADODB.Recordset
Dim Mystr As String
ADOcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=d:\db1.mdb" '修改自文件路径及名称
Print "表名", "记录数"
Set ADOrs = ADOcn.OpenSchema(adSchemaTables)
Do Until ADOrs.EOF
If ADOrs("Table_type") = "TABLE" And Left(ADOrs("Table_name"), 7) <> "~TMPCLP" Then
Mystr = "select * from " & ADOrs!table_name
Yourt.Open Mystr, ADOcn, 3, 1
Print ADOrs!table_name, str(Yourt.RecordCount)
ADOrs.MoveNext
Yourt.Close
Set Yourt = Nothing
Else
ADOrs.MoveNext
End If
Loop
End Sub
Private Sub Command1_Click()
Dim ADOrs As New Recordset
Dim ADOcn As New ADODB.Connection
Dim Yourt As New ADODB.Recordset
Dim Mystr As String
ADOcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=d:\db1.mdb" '修改自文件路径及名称
Print "表名", "记录数"
Set ADOrs = ADOcn.OpenSchema(adSchemaTables)
Do Until ADOrs.EOF
If ADOrs("Table_type") = "TABLE" And Left(ADOrs("Table_name"), 7) <> "~TMPCLP" Then
Mystr = "select * from " & ADOrs!table_name
Yourt.Open Mystr, ADOcn, 3, 1
Print ADOrs!table_name, str(Yourt.RecordCount)
ADOrs.MoveNext
Yourt.Close
Set Yourt = Nothing
Else
ADOrs.MoveNext
End If
Loop
End Sub
全部回答
- 1楼网友:渊鱼
- 2021-01-29 03:24
1,引入命名空间
2,定义连接字符串
3,定义connection对象
4,写sql语句
5,创建command对象
6,try{}catch{}finally{}
7,打开数据库连接
8,创建datareader对象
9,逐行读取datareader对象查询的结果
0,关闭datareader对象
11,关闭数据库连接
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯