检查access数据库中是否存在某个名字的表

可以把本功能写成一个函数,函数的处理过程描述如下:

  1. 首先调用adodb.connection对象中的openSchema函数,这样会得到一个Recordset,其中每一条“纪录”对应着数据库中的一张表,“纪录”的每个“字段”包含了对应表的某方面信息。其中TABLE_NAME字段包含了对应表的名称
  2. 然后遍历这个Recordset,如果“当前纪录”的TABLE_NAME字段的值和要查找的表的名字一样,证明要查找的表存在。

函数如下所示:

function check_gived_DataTable_exist_or_not(connect_object,name_of_gived_DataTable)
 Do_gived_DataTable_exist=false
 Const adSchemaTables=20 '表明想要得到数据库中“表(table)和视图(view)的集合”
 set RecordSet_about_table_and_view_in_DataBase=connect_object.openSchema(adSchemaTables)
 Do Until RecordSet_about_table_and_view_in_DataBase.EOF
  if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE" then
   if RecordSet_about_table_and_view_in_DataBase("TABLE_NAME")= name_of_gived_DataTable then
     Do_gived_DataTable_exist=true
     exit do  
   end if
  end if
  RecordSet_about_table_and_view_in_DataBase.movenext
 Loop
 
 check_gived_DataTable_exist_or_not=Do_gived_DataTable_exist
end function

注释:

  • connect_object.openSchema(adSchemaTables)这个函数执行后,会得到“数据库中表(table)和视图(view)的集合”,这是一个ADODB.Recordset类型的数据。
  • if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE"这句话把检查范围缩小为“表(table)”。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值