急问:如何判断access数据库中是否存在某个表?

fellingsky 2003-10-30 10:36:28
急问:如何判断access数据库中是否存在某个表?在线等待
...全文
34 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hhjjhjhj 2003-10-30
ADOX也可以
Dim cnn As New ADODB.Connection
Set cat = CreateObject("ADOX.Catalog")
cnn.Open "..............;"
Set cat.ActiveConnection = cnn
For Each tb In cat.Tables
Debug.Print tb.Name
Next
回复
fellingsky 2003-10-30
谢谢!!!
回复
lihonggen0 2003-10-30
DAO访问数据库

用这个,我以前用DAO的时候写的:

Public Function ExistsTable(TName As String) As Boolean
Dim dbAccess As Database
Dim Test As String

On Error Resume Next

Set dbAccess = OpenDatabase(App.Path & "\dbdevice.mdb", False, False)
' 该名字在表名中是否存在。
Test = dbAccess.TableDefs(TName).Name
If Err <> 3265 Then
ExistsTable = True
Err = 0
End If
dbAccess.Close
End Function
回复
lihonggen0 2003-10-30
'*********************************************************
'* 名称:TableExists
'* 功能:判断表是否存在(表名)
'* 用法:TableExists(表名) adoCN是一个access的连接
'*********************************************************
Public Function TableExists(findTable As String) As Boolean
Dim rstSchema As New ADODB.Recordset
Set rstSchema = adoCN.OpenSchema(adSchemaTables)
rstSchema.Find "TABLE_NAME='" & findTable & "'"
If rstSchema.EOF Then
TableExists = False
Else
TableExists = True
End If
rstSchema.Close
End Function


回复
lihonggen0 2003-10-30
'----------------------------------------------------------------------------
'
'Author:lihonggen0
'Date:2003-6-19
'功能:获取access库中表的个数及表的名称
'用ado怎样实现
'工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
'----------------------------------------------------------------------------
Private Sub Form_Load()
Dim adoCN As New ADODB.Connection '定义数据库的连接
Dim strCnn As New ADODB.Recordset
Dim I As Integer
str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Northwind.MDB;Persist Security Info=False"
adoCN.Open str1

Set rstSchema = adoCN.OpenSchema(adSchemaTables)

Do Until rstSchema.EOF
If rstSchema!TABLE_TYPE = "TABLE" Then
out = out & "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
I = I + 1
End If
rstSchema.MoveNext
Loop
MsgBox I
rstSchema.Close

adoCN.Close
Debug.Print out
End Sub

回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-10-30 10:36
社区公告
暂无公告