数据库分页

taogong007 2004-08-11 04:46:38
rs.pagesize=5
rs.open strSQL,Conn1,1,1
pageNo=request.QueryString("pageNo")
if pageNo="" or pageNo<1 then
pageNo=1
end if
rs.AbsolutePage=pageNo

用以上代码为什么还是没有分页啊

麻烦举个简单的例子

...全文
92 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
greencoin 2004-08-11
  • 打赏
  • 举报
回复
<%CurPageName=Request.servervariables("SCRIPT_NAME")%>
<html>
<head>
<title>表数据分页显示</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<Script Language="JavaScript">
function mOvr(src,clrOver){
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = clrOver;
}
}
function mOut(src,clrIn) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}
</Script>
<Script Language="VBScript">
Sub gopage()
If window.event.keycode=13 Then ' 若按回车键
pno=document.frmPage.pageno.value ' 获得文本框中输入的页号
window.location.href="<%=CurPageName%>?pageno=" & pno
End If
End Sub
</Script>
</head>
<body bgcolor="#FFFFFF">
<div align="center"><h2>数据表分页显示</h2></div>
<%
Const adOpenKeyset=1
Const adLockReadOnly=1
Const adCmdText=&H0001
fhsql="select * from teacher"
databasePath=Server.MapPath("/DataBase/office.mdb")
set RS=Server.CreateObject("ADODB.RecordSet")
cnstr="PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source=" & databasePath
RS.Open fhsql,cnstr,adOpenKeyset,adLockReadOnly,adCmdText
RS.PageSize=8 ' 设置每页显示的记录数
If Request.Querystring("pageno")="" Then ' 查询所要显示的页号
RS.AbsolutePage=1 ' 若未指定,则显示第1页
Else
RS.Absolutepage=Request.Querystring("pageno") ' 设置所要显示的页号
End If
' 下面通过累加方式,构造导航栏的内容
title="<form Name='frmPage'><div align='center'>第 " & Rs.AbsolutePage & "/" & Rs.PageCount & "页  共" & Rs.RecordCount & "条记录  "
If Rs.AbsolutePage>1 Then ' 若当前页号大于1,则上一页有效
title=title & "<a href=" & CurPageName & "?pageno=" & Rs.AbsolutePage-1 & ">上一页</a>"
Else
title=title & "上一页"
End if
If Rs.AbsolutePage<Rs.PageCount Then
title=title & "  " & "<a href=" & CurPageName & "?pageno=" & Rs.AbsolutePage+1 & ">下一页</a>"
Else
title=title & "  下一页"
End If
If Rs.AbsolutePage>1 Then
title=title & "   " & "<a href=" & CurPageName & "?pageno=1>首页</a>"
Else
title=title &"   首页"
End If
If Rs.AbsolutePage<Rs.PageCount Then
title=title & "  " & "<a href=" & CurPageName & "?pageno=" & Rs.PageCount &">尾页</a>"
Else
title=title & "  尾页"
End If
title=title & "  第<Input type='text' Name='pageno' onKeyPress='gopage()' size=4>页</div></form>"
Response.write title ' 输出导航栏
Response.write "<table border=0 align=center width='100%'><tr bgcolor=#000080>"
For num=0 To rs.Fields.count-1
Response.write "<td><font color=#ffffff>"+RS.Fields(num).Name+"</td>"
Next
Response.write "</font></tr>"
LineNo=1
Do While NOT RS.EOF AND LineNo<=RS.PageSize ' 输出当前页的内容
Response.write "<TR bgColor=#f6f6f6 onMouseOver=mOvr(this,'#E7E9CF'); onMouseOut=mOut(this,'#F6F6F6');>"
For num=0 To RS.Fields.count-1
fdvalue=RS(num)
If isnull(fdvalue) Then
Response.write "<td> </td>"
Else
If RS(num).Name="联系方式" Then
If instr(rs(num),"@")<>0 Then ' 若为Email地址
Response.write "<td><a href=mailto:" & trim(Rs(num)) & ">" & trim(Rs(num)) & "</a></td>"
Else
Response.write "<td>" & Rs(num) & "</td>"
End If
Else
Response.write "<td>" & Rs(num) & "</td>"
End If
End If
Next
RS.MoveNext
Response.write "</tr>"
LineNo=LineNo+1
Loop
RS.close
%>
</body>
</html>
annyking 2004-08-11
  • 打赏
  • 举报
回复
rs.open strSQL,Conn,3,3
wjh6of6agriculture 2004-08-11
  • 打赏
  • 举报
回复
先open再设置页数,参考下面
Rst.Open GetSearchSQL,Conn,1,1
Rst.PageSize=Int_CountOfPage
Int_TotalPage=Rst.PageCount
If Request.ServerVariables("REQUEST_METHOD")="POST" Then
Page=Trim(Request.Form("page"))
Else
Page=Int(Request.QueryString("page"))
End If
If IsNumeric(Page) Then
Page=Int(Page)
If Page<1 Then
Page=1
End If
If Page>Int_TotalPage Then
Page=Int_TotalPage
End If
Else
Page=1
End If
Rst.AbsolutePage=Page
Rst.CacheSize=Int_CountOfPage
  • 打赏
  • 举报
回复
第一个写错了,这句你试试
  • 打赏
  • 举报
回复
pageNo=CLng(request.QueryString("pageNo"))
  • 打赏
  • 举报
回复
CLng(pageNo=request.QueryString("pageNo"))

28,390

社区成员

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

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