关于 on error resume next.请指点。

myhon 2003-08-03 11:34:00
关于 on error resume next.
举个例子:
1.
<%
on error resume next
sqlStr="insert into users(uerID) values('" & userId & "')"
'userId 是关键字,执行前不检测userId 是否已存在,。
conn.execute(sqlStr)
if conn.errors.count>0 then
response.write "insert error!"
response.end
end if
%>
===========================================
2.
<%
sqlStr="select userId from users where userId='" & userId & "'"
set rs=conn.execute(sqlStr)
if not(rs.eof and rs.bof) then
response.write "insert error!"
response.end
else
sqlStr="insert into users(uerID) values('" & userId & "')"
conn.execute(sqlStr)
end if
%>

1和2 用那种好呢?

...全文
43 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
myhon 2003-08-03
  • 打赏
  • 举报
回复
if not(rs.eof and rs.bof) then '''''更改为:if rs.eof then

错了吧。
if rs.eof then ''''查询为空

if not(rs.eof and rs.bof) then ''''查询不为空

查询不为空时才提示重名。

qdlanghua 2003-08-03
  • 打赏
  • 举报
回复
1.
<%
on error resume next
sqlStr="insert into users(uerID) values('" & userId & "')"
'userId 是关键字,执行前不检测userId 是否已存在,。
conn.execute(sqlStr)
if conn.errors.count>0 then '''''更改为:if Err.Number>0 then
response.write "insert error!"
response.end
end if
%>
更改为

2.
<%
sqlStr="select userId from users where userId='" & userId & "'"
set rs=conn.execute(sqlStr)
if not(rs.eof and rs.bof) then '''''更改为:if rs.eof then
response.write "insert error!"
response.end
else
sqlStr="insert into users(uerID) values('" & userId & "')"
conn.execute(sqlStr)
end if
%>

'我倾向于第二种
night_song 2003-08-03
  • 打赏
  • 举报
回复
为什么我用 insert into 语句时老是出错!也是照那么写的,试了好多次,咋就提示我语法错误!
fengchu2 2003-08-03
  • 打赏
  • 举报
回复
第二种好!
myhon 2003-08-03
  • 打赏
  • 举报
回复
我想知道为什么。
那种效率高呢?
如果表中有100k条记录。
lyilei 2003-08-03
  • 打赏
  • 举报
回复
感觉是第二种好一些吧!
myhon 2003-08-03
  • 打赏
  • 举报
回复
第一种他也录不进去呀.
根据conn错误代码,返回错误.
fxbird 2003-08-03
  • 打赏
  • 举报
回复
这还用问,当然是第二种了。主键又不能重复。
smuzy 2003-08-03
  • 打赏
  • 举报
回复
第二种推荐使用

是不是select count(*) 更好一些呢?
herman_chow 2003-08-03
  • 打赏
  • 举报
回复

if not(rs.eof and rs.bof) then

更改为:if not rs.bof then

28,391

社区成员

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

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