注册 登录
编程论坛 ASP技术论坛

ASP 分页最后一页出错,耱高手指点!

tanwei0775 发布于 2014-05-08 09:55, 860 次点击
好几天也分不出来,只好来求高手指点!
问题是:做一个电脑知识的网站,在显示知识类型标题列表的时候,有多页,每页显示5条记录,到最后一页在显示“首页 上一页 下一页 最后一页”的地点出现:ADODB.Field 错误 '80020009'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/tanwei/zstype.asp,行 0 ”
情况:ACCESS2003版数据表结构:zxid(自动编号),zstitle(文本),zstype(文本)      注:编号,标题,类型
表内有约30条记录,类型有:ASP编程,办公使用,数据库,电脑维护  各在几条记录。
做两个页面:第一页是导航页:leibaio.asp
具体代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head>
<body>
<table width="200" border="0">
  <tr>    <td>文章类型</td>  </tr>
  <tr>    <td><a href="zstype.asp?xx=ASP编程">ASP编程</a></td>  </tr>
  <tr>    <td><a href="zstype.asp?xx=电脑维护">电脑维护</a></td>  </tr>
  <tr>    <td><a href="zstype.asp?xx=办公使用">办公使用</a></td>  </tr>
  <tr>    <td><a href="zstype.asp?xx=数据库">数据库</a></td>  </tr>
</table>
</body></html>

另一个页面显示列表页:zstype.asp
具体代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>知识文章列表</title></head>
<body>
<%
dim connstr,conn,sql,rs
connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("ttw.mdb")
set conn=server.createobject("ADODB.Connection")
conn.open connstr
if err then
    response.write "数据库连接错误!"
    set conn=nothing
    response.end
end if
%>

<%
dim zsty
zsty=request("xx")
exec="select * from zs where zstype='"&zsty&"' order by zstime desc"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<table width="780" border="1">
 <tr class="taright1"> <td><h4>知识标题</h4></td>
                       <td width="14%"><h4>知识类别</h4>   </td> </tr>
 <%
rs.pagesize=5
curpage=Request.QueryString("curpage")
if curpage="" then curpage=1
rs.absolutepage=curpage
%>
 
<%
for i= 1 to rs.pagesize
if rs.eof    then
exit for
end if
%>
  <tr>    <td width="86%" height="18" class="xline"><%=left(rs("zstitle"),30)%></td>
             <td height="18" class="xline"><% =rs("zstype")%></td>   </tr>
<%
rs.movenext
next

%>   

 <tr class="taright1">
 <td colspan="2">
 <%if curpage=1 then%>
首页
<%else%>
<a href="?xx=<% =rs("zstype")%>&curpage=1">首页</a>
<%end if%>

<%if curpage=1 then%>
上一页
<%else%>
<a href="?xx=<% =rs("zstype")%>&curpage=<%=curpage-1%>">上一页</a>
<%end if%>

<%if rs.pagecount<curpage+1 then%>
下一页
<%else%>
<a href="?xx=<% =rs("zstype")%>&curpage=<%=curpage+1%>">下一页</a>
<%end if%>

<%if rs.pagecount<curpage+1 then%>
尾页
<%else%>
<a href="?xx=<% =rs("zstype")%>&curpage=<%=rs.pagecount%>">尾页</a>
<%end if%>
当前第<%=curpage%>页,共有<%=rs.pagecount%>页,共有:<%=rs.recordcount%>条记录</p></span>   </td>
 </tr>
</table>
</body></html>


原文件及数据库在附件。
只有本站会员才能查看附件,请 登录
8 回复
#2
hu9jj2014-05-08 19:31
最后一页出错,会不会是记录集数据结束后没有跳出循环?
#3
tanwei07752014-05-09 08:22
已经做了跳出了,
<%
 for i= 1 to rs.pagesize
 if rs.eof    then
 exit for
 end if
 %>   这不是跳出了吗?

还有一个现象:
在下一页的链接中如果不带参数是不会出错的,因为我的文章类型有ASP编程,办公使用,数据库,电脑维护等类型,表中字段名为ZSTYPE,所以在

<%else%>
 <a href="?xx=<% =rs("zstype")%>&curpage=<%=curpage+1%>">下一页</a>
 <%end if%>
处有中xx==<% =rs("zstype")%>参数,如果是不带参数,整个表的数据都显示,则不会出错~!
#4
tanwei07752014-05-09 08:22
已经做了跳出了,
<%
 for i= 1 to rs.pagesize
 if rs.eof    then
 exit for
 end if
 %>   这不是跳出了吗?

还有一个现象:
在下一页的链接中如果不带参数是不会出错的,因为我的文章类型有ASP编程,办公使用,数据库,电脑维护等类型,表中字段名为ZSTYPE,所以在

<%else%>
 <a href="?xx=<% =rs("zstype")%>&curpage=<%=curpage+1%>">下一页</a>
 <%end if%>
处有中xx==<% =rs("zstype")%>参数,如果是不带参数,整个表的数据都显示,则不会出错~!
#5
xzlxzlxzl2014-05-09 08:37
没有调试环境,我觉得应该去掉一个读数据库,代码如下:
<a href="?xx=<%=rs("zstype")%>&curpage=<%=rs.pagecount%>">尾页</a>
红色部分去掉
<a href="?xx&curpage=<%=rs.pagecount%>">尾页</a>
#6
tanwei07752014-05-12 08:56
谢谢大家的解答!又学会了另外的分页方法!
#7
tanwei07752014-05-12 08:56
谢谢大家的解答!又学会了另外的分页方法!
1