当前位置:编程学习 > asp >>

ASP判断表是否存在

ASP如何判断数据库表是否存在

我想写一个语句

表是否存在的判断语句

if 表存在 then

response.write “表存在”

else

“代码:新建这个表”

response.write “新建表完成”

end if

追问:

注释下可以吗 谢谢 打开数据库后面的有些看不懂

答案:on error resume next '屏蔽出错提示
rs.open "table1",conn1 '打开你要的表table1

if not err.number=0 then '如果表不存在
Err.Clear '清除该错误

Response.write "表不存在" '提示表不存在

else

Response.write "表存在" '提示表存在
end if

Function GetTableName(DBpath)
dim rs
dim Conn
set conn = server.CreateObject("ADODB.Connection")
conn.Open "Dbq=" & DBpath & ";Defaultdir=;Driver={Microsoft Access Driver (*.Mdb)};Driverid=25;Fil=Ms Access;Implicitcommitsync=Yes;Maxbuffersize=512;Maxscanrows=8;Pagetimeout=5; Safetransactions=0;Threads=3;Usercommitsync=Yes;", "Administrator", "admin"
set rs = Conn.OpenSchema(20)

do while not rs.eof
if rs("table_type") ="TABLE" then
GetTablename =GetTableName & "," & rs("TABLE_NAME")
end if
rs.moveNext
loop
rs.close
conn.Close
set rs = nothing
End Function

response.write GetTableName("C:\yours.mdb")
if instr(GetTableName("C:\yours.mdb"),"表名")<>0 Then
response.write "表存在"
else

sql="create table yourtable (y_id integer identity(1,1) primary key,y_name varchar(50) not null default '张三')"

conn.ExeCute(SQL)
response.write "新建表完成"
end if

上一个:asp.net高手救急!!!
下一个:asp用户找回密码功能

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,