ASP中查询数据库ID为空处理

来源:百度知道 编辑:UC知道 时间:2024/06/30 10:59:42
我在ASP里面处理数据库ID的时候,当ID为空,运行时出现:
ADODB.Field 错误 '80020009'

BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。

/cn/job_apply.asp,行 0

报错

对应文件处理ID为:

<%

dim rs,sql,id

id=Trim(Request.QueryString("id"))

id=SafeRequest(id,0)

if id="" or (not isNumeric(id)) then
Response.Redirect "job.asp"
Response.End()
end if

set rs= Server.CreateObject("adodb.recordset")

sql="select job from job where id="&id

rs.open sql,conn,1,1
%>

设置的是当ID为空时,就直接跳转到JOB.ASP页面,可是运行时却不是,请问如何修正。谢谢

查询完加个判断

if id="" or (not isNumeric(id)) then
Response.Redirect "job.asp"
Response.End()
end if
这段只是对id进行校验

要在查询以后再加上一个转向判断

代码如下:
<%

dim rs,sql,id

id=Trim(Request.QueryString("id"))

id=SafeRequest(id,0)

if id="" or (not isNumeric(id)) then

else

set rs= Server.CreateObject("adodb.recordset")

sql="select job from job where id="&id

rs.open sql,conn,1,1
if rs.eof and rs.bof then
Response.Redirect "job.asp"
else

..................
end if
end if
%>

end if 改成else, end if移到后面

不是这儿的问题,这个问题我想是,ID不为空,不过是数据库里没有这条记录,查询为空,你就输出了,是那儿的问题,在查询完要用个,
if not rs.eof then
输出
else
无记录
end if

恩,查询完加个判断