檢查SQL Server中資料表是否存在

摘要:檢查SQL Server中資料表是否存在

''' <summary>檢查 SQL 資料庫中是否存在此資料表</summary>  
''' <param name="TableName">要搜尋的資料表名稱</param>  
Public Function IsSQLTableExist(ByVal TableName As String) As Boolean  
    Try  
        Using con_SQL = GetSQLConnection()  
            con_SQL.Open()  
  
            Dim DT As DataTable  
            Dim restrictions() As String = {Nothing, Nothing, TableName, Nothing}  
            DT = con_SQL.getschema("Tables", restrictions)  
  
            If DT.Rows.Count > 0 Then  
                Return True  
            Else  
                Return False  
            End If  
        End Using  
  
    Catch ex As Exception  
        MsgBox(ex)  
    End Try  
End Function