分页显示的问题,总是说游标设置的不正确,在线等待
在参考一个分页显示的程序时总是不能得到正确结果,同学们请大家帮帮我这个错误出在那里
:
<!--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>