CDaoDatabase访问数据库,如何判断一个表是否存在?

解决方案 »

  1.   

    Dim CAT As New ADOX.Catalog
    Dim TBL As ADOX.TableSet CAT.ActiveConnection = Me.Application.CurrentProject.ConnectionFor Each TBL In CAT.Tables
        If Left(TBL.Name, 4) <> "MSys" Then
              Debug.Print TBL.Type & ":" & TBL.Name
        End If
    Next
      

  2.   

    从逻辑上是看明白意思:
    我是用VC,初学,觉得你写的代码不象VC,能解释一下吧。非常感谢!!
      

  3.   

    用try{
        ...
    }catch(...)
    {}可以捕获相关错误!也许可以达到你的目的
      

  4.   

    to  archoo(archoo):
    用try{
      }catch(){
      }
    应该可以,
    但是:
    我是用CDaoTableDef.Open()打开表,cathch()时如何捕获表不存的情况呢.
    我查了相关信息没发现怎么捕获。
    请指教!!
      

  5.   

    我是ADO,是通用于VB和VC的。可惜我不懂VC,你把相关地方改成VC的就差不多了。
      

  6.   

    参考:
    http://www.jiafangyifang.com/news/newsdata/2002_06_20/4/20020620100709.htm
      

  7.   

    是访问access数据库吧,用这个SQL语句:select [name] from msysobjects where type=1 and flags=0如果是SQL SERVER数据库,用:select [name] from sysobjects where xtype='u'
      

  8.   

    to njtlxm(njtlxm) :
    DB:access
    select [name] from msysobjects where type=1 and flags=0
    上面的查询语句单独执行可以。
    放在程序中(Dao访问数据库)
    提示:select [name] from msysobjects where type=1 and flags=0
    请帮忙!!^_^^_^
      

  9.   

    sorry:
    to njtlxm(njtlxm) :
    DB:access
    select [name] from msysobjects where type=1 and flags=0
    上面的查询语句单独执行可以。
    放在程序中(Dao访问数据库)
    提示:不能读取记录;在 'msysobjects' 上没有读取数据权限请帮忙!!^_^^_^
      

  10.   

    不好意思,这个问题我确实没有考虑到。我刚才用OLE DB方式也发生了你所说的现象。等我继续试验,测试成功后会给你一个答复。如果你有什么好的办法,请及时告诉我。
      

  11.   

    参考:
    http://access911.net/index.asp?board=4&mode=3&recordid=71FAB11E11DC
    结贴:njtlxm(njtlxm) (10),zhengjialon(2)