分页显示的问题,总是说游标设置的不正确,在线等待

sunsunwang810812 2003-12-17 09:09:38
在参考一个分页显示的程序时总是不能得到正确结果,同学们请大家帮帮我这个错误出在那里

<!--meteadata name="microsoft activex data object2.5 library"
type="typelib" uuid="{00000205-0000-0010-8000-00aa006d2ea4}"-->
<% @ language=vbscript%>
<%
response.expires=0 '使浏览器缓存得页面立即过期,使每次访问该页面都是从服务器上下载新页面
%>
<%
const intpagesize=3 '每页显示3条纪录
dim intcur,inttotal,i 'intcur确定当前页数,inttotal 确定总页数,i循环变量
dim cn,rst,strsql
if request.servervariables("content_length")=0 then
intcur=1 '如果客户端所提交的内容长度是空则当前页是1
else
intcur=cint(request.form("curpage"))'从表单中获得当前页号
select case request.form("page")
case "首页"
intcur=1
case "上一页"
intcur=intcur-1
case "下一页"
intcur=intcur+1
case "尾页"
intcur=cint(request.form("lastpage"))
end select
end if

set cn=server.createobject("adodb.connection")
cn.ConnectionString="DSN=netbs;UID=sunwang;PWD=wsnedy" '做联接前的准备工作
cn.open '如数剧源ODBC进行联接

set rst=server.createobject("adodb.recordset")


rst.cursorlocation=adUserClient '这两行有问题
rst.cursortype=adOpenStatic


rst.cachesize=intpagesize 'cachesize决定了一次从数据库取多少条记录到服务器缓冲区,要是在记录集中移动则是在缓冲区中移位而不是在库中进行移动,速度加快

strsql="select * from books"
rst.open strsql,cn,,,adcmdtext
rst.pagesize=intpagesize

if not rst.eof then
rst.absolutepage=intcur '设置当前记录所在页号
end if
inttotal=rst.pagecount'获得总页数,其大小由pagesize决定
%>
<html>
<title>分页显示小说 </title>
<body>
<b>小说有<%=rst.recordcount%>本&nbps;
共<%=inttotal%>页&nbps;当前是第<%=intcur%>页</b><p>
<center>
<form action="sample26.asp" method="post">
<input type="hidden" name="curpage" value="<%=intcur%>">
<input type="hidden" name="lastpage" value="<%=inttotal%>">
<input type="submit" name="page" value="首页">&nbps;&nbps;

<%if intcur>1 then%>
<input type="submit" name="page" value="上一页">&nbps;&nbps;
<%end if%>

<%if intcur<>inttotal then%>
<input type="submit" name="page" value="下一页">&nbps;&nbps;
<%end if%>

<input type="submit" name="page" value="尾页">&nbps;&nbps;
</form></p>

<%
i=0
response.write"<table border=1>"
do while not rst.eof and i<rst.pagesize
response.write"<tr height=12><td width=20>"&rst.absoluteposition&"</td>" '设置或返回当前记录在记录集中的顺序位置
response.write"<td width=160>"&rst("bookname")&"</td>"
response.write"<td width=180>"&rst("writer")&"</td>"
response.write"<td width=40>"&rst("price")&"</td></tr>"

rst.movenext '移到下一条纪录

i=i+1
loop

response.write"</table>"
response.write"</center>"
rst.close
%>
</body>
</html>
...全文
37 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsunwang810812 2003-12-17
  • 打赏
  • 举报
回复
patchclass(黑翼)感谢你,我的问题按你的方法解决了,但我不明白的是rst.cursorlocation不是只有1和2两种属性值吗为什么这里是3呢
patchclass 2003-12-17
  • 打赏
  • 举报
回复
rst.cursorlocation=3
rst.cursortype=3
Tal 2003-12-17
  • 打赏
  • 举报
回复
rst.cursorlocation=adUserClient '这两行有问题
rst.cursortype=adOpenStatic


rst.cachesize=intpagesize 'cachesize决定了一次从数据库取多少条记录到服务器缓冲区,要是在记录集中移动则是在缓冲区中移位而不是在库中进行移动,速度加快

strsql="select * from books"
rst.open strsql,cn,,,adcmdtext
以上改为如下即可:
rst.open strsql,cn,1,1

28,407

社区成员

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

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