关于分页的问题!!在线等!!

phili1999 2002-08-27 11:50:58
我做了一个分页的测试,为什么得到的AbsolutePage总是-1
下面是测试代码,记录查出有20条
connstr="Driver={SQL Server};server=(local);uid=sa;pwd=12345;database=SaleNet;"
set conn=server.createObject("ADODB.Connection")
conn.open connstr
set rs=server.CreateObject ("ADODB.Recordset")
rs.Open "tbl_RenderPerDay1",conn,1,3
rs.PageSize =10
Response.Write rs.AbsolutePage
Response.Write rs.RecordCount
Response.Write rs.PageCount
...全文
172 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxlh 2002-08-27
  • 打赏
  • 举报
回复
给你个例子,不过数据库是ACCESSD的。给一下就可以了
<%
dim xSQL,rowcount
rowcount=0


xSQL= "select * from news where 类型='学院' and hot<>1 order by 加入日期 Desc "
set Connect=Server.CreateObject("ADODB.Connection")
Connect.Open "driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("data.mdb")
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open xSQL,connect,3,3

page=trim(request("page"))

if page="" then
page=1
end if
rs.PageSize=10
page=cint(page)

if page<1 then page =1
if page>rs.PageCount then page=rs.PageCount

rs.AbsolutePage=page
%>

<html>
<head>
<title>更多新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.txt { font-size: 14px; color: #ff0000; text-decoration: none; font-weight: bold}
-->
</style>

<link rel="stylesheet" href="mycss.css" type="text/css">
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>

<script ID=clientEventHandlersJS language="JavaScript">
<!--
function page_onchange() {
thisForm.submit();}

//-->
</script>

</head>

<body bgcolor="#FFF1e6" leftmargin="0" topmargin="0">
<table width="776" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="60" valign="top"><img src="images/heut_news.GIF" width="776" height="80"></td>
</tr>
</table>
<hr noshade align="center">
<table width="776" border="0" cellspacing="0" cellpadding="0" align="center" height="316">
<tr>
<td width="48" valign="top" height="317"></td>
<td width="8" valign="top" bgcolor="#FFFFFF" height="317"> </td>
<td width="8" valign="top" height="317"></td>
<td valign="top" bgcolor="#FFFFFF" width="20" height="317"><img src="images/news_leftcn.GIF" width="20" height="20"></td>
<td bgcolor="#FFFFFF" height="317" valign="top" width="651"><br>
<form name="thisForm" method="post" action="morenews.asp" target="_self">
<table width="643" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="18" width="37" bgcolor="#CCCCCC">
<div align="center"><font color="#990000">编 号</font></div>
</td>
<td height="18" width="12"> </td>
<td height="18" width="313" bgcolor="#CCCCCC">
<div align="center"><font color="#990000">新闻标题</font></div>
</td>
<td height="18" width="13"> </td>
<td height="18" width="60" bgcolor="#CCCCCC">
<div align="center"><font color="#990000">加入日期</font></div>
</td>
<td height="18" width="12"> </td>
<td height="18" width="66" bgcolor="#CCCCCC">
<div align="center"><font color="#990000">类 型</font></div>
</td>
<td height="18" width="12"> </td>
<td height="18" width="36" bgcolor="#CCCCCC">
<div align="center"><font color="#990000">热 点</font></div>
</td>
</tr>
<tr>
<td height="10"> </td>
<td height="10"></td>
<td height="10" colspan="2"></td>
<td height="10"> </td>
<td height="10"></td>
<td height="10"> </td>
<td height="10"></td>
<td height="10"> </td>
</tr>
<% while not rs.eof and rowcount<rs.PageSize %>
<% rowcount=rowcount+1
NO=(page-1)*rs.PageSize+rowcount
%>
<tr>
<td height="23">
<div align="center"><%=NO%></div>
</td>
<td height="23"> </td>
<td height="23" colspan="2"><a href="shownews.asp?newsid=<%=rs("newsid")%>" target="_blank" class="black"><%=rs("标题")%></a></td>
<td height="23" colspan="2"><%=rs("加入日期")%></td>
<td height="23" width="66">
<div align="center"><%=rs("类型")%></div>
</td>
<td height="23" width="12"> </td>
<td height="23" width="36">
<div align="center">
<% if rs("hot")=1 then %>

<% else %>

<% end if %>
</div>
</td>
</tr>
<% rs.MoveNext %>
<% wend %>
</table>
<hr size="1" noshade align="center" width="645">
<div align="center">
<% if page<>1 then %>
<a href="morenews.asp?page=1" class="black">第一页</a>  
<a href="morenews.asp?page=<%=page-1%>" class="black">上一页</a>  
<% end if %>
<% if page<>rs.PageCount then %>
<a href="morenews.asp?page=<%=page+1%>" class="black">下一页</a>  
<a href="morenews.asp?page=<%=rs.PageCount%>" class="black">最后页</a>     
<% end if %>

<select id=page name="page" LANGUAGE=javascript onchange="return page_onchange()" class="sel" size="1">
<% for i=1 to rs.PageCount %>
<option value=<%=i%> <% IF page= i then %> selected <% end if %>><%=i%></option>
<% next %>
</select>
页 </div>
</form>
</td>
<td width="15" valign="top" bgcolor="#FFFFFF" height="317"><img src="images/news_rightcn.GIF" width="20" height="20"></td>
<td valign="top" width="26" height="317"></td>
</tr>
</table>
<br>
</body>
</html>


Reker熊 2002-08-27
  • 打赏
  • 举报
回复
需要指定打开的游标类型和锁类型(比如rs.open sql,conn,1,1)

RS.OPEN SQL,CONN,A,B
A: ADOPENFORWARDONLY(=0) 只读,且当前数据记录只能向下移动
ADOPENSTATIC(=3) 只读,当前数据记录可自由移动
ADOPENKEYSET(=1) 可读写,当前数据记录可自由移动
ADOPENDYNAMIC(=2) 可读写,当前数据记录可自由移动,可看到新增记录
B: ADLOCKREADONLY(=1) 默认值,用来打开只读记录
ADLOCKPESSIMISTIC(=2) 悲观锁定
ADLOCKOPTIMISTIC(=3) 乐观锁定
ADLOCKBATCHOPTIMISTIC(=4) 批次乐观锁定
gshope 2002-08-27
  • 打赏
  • 举报
回复
rs.Open "tbl_RenderPerDay1",conn,3,1
lishizhen2002 2002-08-27
  • 打赏
  • 举报
回复
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
if rs.eof then
response.write"<center><font color=red>对不起,没有相关信息!</font></center>"
else
intCurPage=request("pagenum") '第几页
'一页几条
rs.pagesize=10

if intCurPage="" then
intCurPage=1
else
intCurPage=cint(intCurPage)
if intCurPage<1 then intCurPage=1
if intCurPage>rs.pagecount then intCurPage=rs.pagecount end if
end if
rs.absolutepage=intCurPage
MeXP 2002-08-27
  • 打赏
  • 举报
回复
改为rs.Open "tbl_RenderPerDay1",conn,3,3试试
ssm1226 2002-08-27
  • 打赏
  • 举报
回复
你不用管这些,使用时
rs.AbsolutePage=intPage
即可
ssm1226 2002-08-27
  • 打赏
  • 举报
回复
服务器光标服务并不是所有的数据服务都支持
ms sql支持
access不支持
ssm1226 2002-08-27
  • 打赏
  • 举报
回复
设置或返回从 1 到 Recordset 对象 (PageCount) 所含页数的长整型值,或者返回以下常量。

常量 说明
AdPosUnknown=-1
AdPosBOF=-2
AdPosEOF=-3
========================================
改动如下:
connstr="Driver={SQL Server};server=(local);uid=sa;pwd=12345;database=SaleNet;"
set conn=server.createObject("ADODB.Connection")
conn.open connstr
set rs=server.CreateObject ("ADODB.Recordset")
'--------------------------------
'光标服务是服务器光标或者客户光标
'2(adUseServer)服务器光标
'3(adUseClient)客户光标
rs.CursorLocation=3
'--------------------------------
rs.Open "tbl_RenderPerDay1",conn,1,3
rs.PageSize =10
Response.Write rs.AbsolutePage
Response.Write rs.RecordCount
Response.Write rs.PageCount

28,391

社区成员

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

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