asp 数据库分页问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 21:18:25
<html>
<head>
</head>
<body>
<%
set cn=server.createobject("adodb.connection")
set cmd=server.createobject("adodb.command")
set rs=server.createobject("adodb.recordset")
cn.connectionstring="driver={sql server};server=.;database=db;uid=sa;pwd="
cn.open()
cmd.activeconnection=cn
cmd.commandtext="select count(sno) from student"
set rs=cmd.execute()
if instr(cstr(rs(0)/2),".") then
pagecount=int(rs(0)/2)+1
else
pagecount=rs(0)/2
end if
if request.querystring("page")="" then
pagea=1
else
pagea=request.querystring("page")
end if
cmd.commandtext="select top 2 * from student where sno not in(select top "+cstr((pagea-1)*2)+&

加一个pageNum变量赋值为2:
pageNum=2

然后把循环条件改为:
do while not rs.eof and pageNum>0

再在循环尾部加一个:
pageNum=PageNum-1

再写原来的:
rs.movenext()
loop

select top 2 * from student