疑问

zzy0000 2004-11-21 10:29:25
<%
nr=request.Form("nr")

set rs=server.CreateObject("adodb.recordset")
sql="select * from movieclass where 类型='"&nr&"'"
rs.open sql,con,1,3

response.Write("sql:"&sql&"<br>")
response.Write("recordcount:"&rs.recordcount&"<br>")

if (rs.eof) and (rs.bof) then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if

rs.close
set rs=nothing
con.close
set con=nothing

response.Redirect("movieclass.asp")

%>

以上是添加类型的代码,但很奇怪,有时添加一个数据库中还没有的类型,也报“该类型已经存在”
页面上输出:
sql:select * from movieclass where 类型='sdfw'
recordcount:1
该影视类型已经存在!

谁能给我解惑!谢谢
...全文
86 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzy0000 2004-11-22
  • 打赏
  • 举报
回复
还是不行
ygjwjj 2004-11-22
  • 打赏
  • 举报
回复
if (rs.recordcount=0) then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if
zzy0000 2004-11-22
  • 打赏
  • 举报
回复
up
zzy0000 2004-11-22
  • 打赏
  • 举报
回复
我改为:
if rs.eof then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if

if not rs.eof then
response.Write("该类型已经存在!")
response.End()
else
rs.addnew
rs("类型")=nr
rs.update
end if
问题还是存在

我加入一条没有的类型,它报已经存在,进数据库中看,它把那条记录添加进了数据库了,说明它已经执行添加语句,但我不明白它为什么报已经存在

以上这现象不是总是出现的

大家帮忙看看,我头都晕了,谢谢
hazen 2004-11-22
  • 打赏
  • 举报
回复
if not rs.eof then
response.Write("该类型已经存在!")
response.End()
else
rs.addnew
rs("类型")=nr
rs.update
end if
ufrshchenw 2004-11-22
  • 打赏
  • 举报
回复
改成
if (rs.eof) or (rs.bof) then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if
hqcsx 2004-11-22
  • 打赏
  • 举报
回复
if not rs.eof then
response.Write("该类型已经存在!")
response.End()
else
rs.addnew
rs("类型")=nr
rs.update
end if
fashchina 2004-11-21
  • 打赏
  • 举报
回复
或者直接写:
if rs.eof then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if
fashchina 2004-11-21
  • 打赏
  • 举报
回复
if (rs.eof) and (rs.bof) then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if

---->


if (rs.eof) or (rs.bof) then
rs.addnew
rs("类型")=nr
rs.update
else
response.Write("该类型已经存在!")
response.End()
end if
deleteall8 2004-11-21
  • 打赏
  • 举报
回复
nr=trim(request.Form("nr"))
zzy0000 2004-11-21
  • 打赏
  • 举报
回复
movieclass.asp 是另一页面

28,390

社区成员

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

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