ASPは、データベースにテーブルが存在するか否かを判断する

1317 ワード

<!--#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

%>