我想判断一个数据库中是否存在xxx表,如果存在则删除,应该怎样做?

解决方案 »

  1.   

    '判断某个表是否存在
    Function ChkTable(ByRef Cnn As ADODB.Connection, TableName As String) As Boolean
            Dim StrSql As String
            Dim Rs As New ADODB.Recordset
            
            On Error Resume Next
            
            StrSql = "Select top 1 * from " & TableName
            Rs.Open StrSql, Cnn, adOpenKeyset, adLockBatchOptimistic
            ChkTable = (Err.Number = 0)
            Err.Clear
            Set Rs = Nothing
    End Function2.
    删除该表.
    STRSQL="DROP TABLE [TABLENAME]"
    Cnn.ExecuteN STRSQL
      

  2.   

    动态建立
    dim conn as new adodb.connection
    dim res as new adodb.recordset
    res.open "select * from 表名" conn,3,3
    if res.eof=res.bof then
     conn.executen "dorp table 表明"
    end if
    方法2
    使用纯SQL语句!留个信箱!