怎么判断access数据库中某个表是否存在

cloudgamer 2006-12-29 03:09:08
<%

rem x=0 表示不存在,x=1 表示存在

strconn="dbq="+server.mappath("zw.mdb")+";defaultdir=;driver={microsoft access driver (*.mdb)};"
set objconn=server.createobject("adodb.connection")
objconn.open strconn
set rsschema=objconn.openschema(20)
rsschema.movefirst

tablename="gd111"
x=0
do until rsschema.eof
if rsschema("table_type")="table" then

if rsschema("table_name")=tablename then
x=1
exit do
end if
end if


rsschema.movenext
loop

if x=0 then response.write"没有找到!!!"

if x=1 then response.write"找到了"


set objconn=nothing
%>

我从网上找来这断代码
但不成功
每次都是"没有找到!!!"
...全文
337 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudgamer 2007-01-09
  • 打赏
  • 举报
回复
等看
  • 打赏
  • 举报
回复
这个是本身可以做自动生成器用的

以后我给演示版本。。。。。脚本版 vb版,如果需要vc版也能很快写出来
cloudgamer 2007-01-08
  • 打赏
  • 举报
回复
love007的方法就可以了
不过liuxiaoyi666的东西好象很有意思哦
cloudgamer 2007-01-08
  • 打赏
  • 举报
回复
看了一下
一头雾水啊
能说一下怎么用么
  • 打赏
  • 举报
回复
http://blog.csdn.net/liuxiaoyi666/archive/2006/12/20/1450981.aspx
cloudgamer 2007-01-04
  • 打赏
  • 举报
回复
看看
zhangjun 2006-12-30
  • 打赏
  • 举报
回复
Dim cn ,strCnn,rstSchema

set cn = server.createobject("ADODB.Connection")
set strCnn = server.createobject("ADODB.Recordset")
set rstSchema = server.createobject("ADODB.Recordset")

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"
strCnn = strCnn & "Data Source=F:\asptest\tree.MDB;"
strCnn = strCnn & "Persist Security Info=False"

cn.Open strCnn

set rstSchema=cn.openSchema(20)
rstSchema.movefirst
Do Until rstSchema.EOF
if rstSchema("TABLE_TYPE")="TABLE" then
response.write rstSchema("TABLE_NAME") & "<br/>"
end if
rstSchema.movenext
Loop
cn.close

'set rstSchema = nothing
'set cn = nothing
竹林听雨2005 2006-12-30
  • 打赏
  • 举报
回复
on error goto errHandle:
select count(1) from tablename
....

errHandle:
Response.write("表不存在!")

这种方法不知道可不可以,没测试,原理上应该能行得通
minkingshine 2006-12-29
  • 打赏
  • 举报
回复
用异常处理
dim isExist
isExist=o
try
{
//connect to the database
//open the table (tablename)
isExist=1
}
catch
{
//
}
finnally
{
//dispose the connection
}
cloudgamer 2006-12-29
  • 打赏
  • 举报
回复
cow8063的方法可以
但有时候不知道是不是因为没有建表而出错啊
lcw321321 2006-12-29
  • 打赏
  • 举报
回复
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablename]')
then

else

sql 2000里面的,不知道通用不
cow8063 2006-12-29
  • 打赏
  • 举报
回复
select * from tablename
如果没有此表会出错,根据此判断就行

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧