各位大虾:
    在VB应用程序中我连接到ACCESS数据库,但不知如何检测是否存在某一个数据表。请详细写明,谢谢!

解决方案 »

  1.   

    我有个很损的办法:
    SQL="Select * from ttttttttttttttttttt"
    “ttttttttttttttttttt“是一个不存在的表,然后执行这个SQL会返回一个特定的
    Err.ID
    然后比较Err.ID就知道你不确定的表是不是存在了,呵呵
      

  2.   

    Sorry:
    是Err.Number 不是Err.ID
      

  3.   

    我没有用过ACCESS,不知道ACCESS有没有像SQL一样在SYSOBJECTS中保存数据对象
      

  4.   

    如果用DAO就很方便了。dim db as database,i as integerset db=dbengien.opendatabase("yourdatabase")
    for i =0 to db.tabeldefs.count-1
    debug.print db.tabeldefs(i).name
    nextdb.close这样就可以获取数据库中所有的表名了。
      

  5.   

    参考,稍改下就好了
    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 = 0ErrorHandler:
        Exit Function
    GetTables_ErrorHandler:
        Screen.MousePointer = 0
        ShowErrMsg ("GetTables")
        Resume ErrorHandlerEnd Function
      

  6.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=8159