高分求教大虾如何检查在ACCESS数据库中是否存在某个表?

szyhp 2003-04-11 11:27:43
各位大虾:
在VB应用程序中我连接到ACCESS数据库,但不知如何检测是否存在某一个数据表。请详细写明,谢谢!
...全文
69 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
DimVar 2003-04-11
  • 打赏
  • 举报
回复
参考,稍改下就好了
Function GetTables(cnn As ADODB.Connection) As Boolean
'Purpose : Get table names from the Connection given
'Input : cnn, ther ADODB.Connection
'Output : TRUE/FALSE
'

On Error GoTo GetTables_ErrorHandler
Screen.MousePointer = 11

Dim rstSchema As ADODB.Recordset
cboTablesName.Clear

Set rstSchema = cnn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))


Do Until rstSchema.EOF
If StrComp(Left(rstSchema!TABLE_NAME, 4), "MSys", vbTextCompare) <> 0 Then
cboTablesName.AddItem rstSchema!TABLE_NAME
End If
rstSchema.MoveNext
Loop

rstSchema.Close
Set rstSchema = Nothing

Screen.MousePointer = 0

ErrorHandler:
Exit Function
GetTables_ErrorHandler:
Screen.MousePointer = 0
ShowErrMsg ("GetTables")
Resume ErrorHandler

End Function
qbilbo 2003-04-11
  • 打赏
  • 举报
回复
如果用DAO就很方便了。

dim db as database,i as integer

set db=dbengien.opendatabase("yourdatabase")
for i =0 to db.tabeldefs.count-1
debug.print db.tabeldefs(i).name
next

db.close

这样就可以获取数据库中所有的表名了。
showflow 2003-04-11
  • 打赏
  • 举报
回复
我没有用过ACCESS,不知道ACCESS有没有像SQL一样在SYSOBJECTS中保存数据对象
ouyi0901 2003-04-11
  • 打赏
  • 举报
回复
Sorry:
是Err.Number 不是Err.ID
ouyi0901 2003-04-11
  • 打赏
  • 举报
回复
我有个很损的办法:
SQL="Select * from ttttttttttttttttttt"
“ttttttttttttttttttt“是一个不存在的表,然后执行这个SQL会返回一个特定的
Err.ID
然后比较Err.ID就知道你不确定的表是不是存在了,呵呵
fleshboy 2003-04-11
  • 打赏
  • 举报
回复
对,用OpenSchema!
lihonggen0 2003-04-11
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=8159

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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