当前位置: 代码迷 >> ASP >> asp怎么判断表名
  详细解决方案

asp怎么判断表名

热度:127   发布时间:2012-03-31 13:13:26.0
asp如何判断表名
ASP在查询SQL数据库时,如果查询的表名在SQL中没有,应该如何弹出错误?

------解决方案--------------------
VBScript code

<%
sConn = "Provider=SQLOLEDB;Data source=127.0.0.1;Initial Catalog=DB;User ID=sa;Password=sa;"
sTable = "table_name"
Set conn = CreateObject("ADODB.Connection")
conn.Open sConn
Set oCat = CreateObject("ADOX.Catalog")
Set oCat.ActiveConnection = conn
Set colTables = oCat.Tables
b = False
For Each t In colTables
    If t.Name = sTable Then
        b = True
        Exit For
    End If
Next
conn.Close
Set conn = Nothing
Set oCat = Nothing
Set colTables = Nothing

If b Then
    Response.Write "存在" & sTable
Else
    Response.Write "不存在" & sTable
End If

%> 
  相关解决方案