ASP判断数据库中表是否存在
<!--#include file="../conn.asp" --> <% Function CheckTable (myTable) '列出数据库中的所有表 dim rs,getTableName set rs=conn.openSchema(20) rs.movefirst do Until rs.EOF if rs("TABLE_TYPE")="TABLE" then 'response.write rs("TABLE_NAME") & "," getTableName=getTableName+rs("TABLE_NAME")&"," end if rs.movenext loop rs.close set rs=nothing '判断数据库中是否存在此表(下面两行代码使待比较表和指定表前后都加上豆号,以精确比较) dim getTableName2,myTable2 getTableName2=","&getTableName '此字符串后面已经有豆号 myTable2=","&myTable&"," If instr(getTableName2,myTable2)<>0 Then CheckTable=1 '存在 else CheckTable=0 '不存在 end if End Function Function ChkTable(mytable) on error resume next dim rs set rs = server.CreateObject("adodb.recordset") rs.open "select top 1 * from "&mytable,conn,1,1 if not err.number=0 Then 'response.write err.number Err.Clear '清除该错误 ChkTable= 0 '"不存在" else ChkTable=1 '"存在" end If rs.close Set rs=Nothing End Function %> <% '下面是测试代码 If ChkTable("Yao_User")=1 then ' Yao_User 是自己连的数据库中的表 Response.Write("Yes") Else Response.Write("No") End If %>