分页问题

dreamcast 2002-05-14 11:02:31
我在做分页浏览时,以前用Excel时先设置rs.pagesize后设置
rs.AbsolutePage = page 和rs.AbsolutePosition = num来设置当前页和当前记录。现在用sqlserver时对rs.AbsolutePage 和rs.AbsolutePosition赋值总提示出错。是不是两个数据库的操作不一样,请大家看一看。
...全文
23 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shadowkiss 2002-05-14
我喜欢自己做分页程序 :)
回复
ChinaOk 2002-05-14
一个简单的分页例子
<!--#include file="sqlconn.asp"-->

<html>
<head>
<meta http-equiv="Content-Language" content="English">
<meta name="companylist" content="FrontPage.Editor.Document">
<title>CompanyList</title>
</head>

<body>
<%
dim iLen '每页显示的数量
iLen=3
dim TotalNum '公司的总数量
dim page,allpage
dim name
name=request("name")

Set rs=Server.Createobject("ADODB.Recordset")
rs.pagesize=iLen
rs.CursorLocation=3

SQL="select gongname,gongid from tabgong "
if name<>"" then
if ucase(name)<>"[ALL]" then
Sql=SQL & "where gongname like '%" & Replace(name,"'","''") & "%'"
end if
end if
SQL=SQL & " order by gongid desc"
rs.open SQL,conn,1,1

TotalNum=rs.RecordCount
if (TotalNum mod iLen)=0 then
allpage = TotalNum/iLen
else
allpage = int(TotalNum/iLen)+1
end if

if request.querystring("page") = "" then
page = 1
else
page = cint(request.querystring("page"))
'防止越界
if page<1 then page=1
if page>allpage then page=allpage
end if
'定位到当前页
rs.absolutepage=page
%>

<p>
<img border="0" name="IMGSEARCH" src="pic/mainmanager-search.gif">
<a href="add.asp">
<img border="0" name="IMGADD" src="pic/mainmanager-add.gif" title="Add..."></a>
<img border="0" name="IMGDEL" src="pic/mainmanager-delete.gif">
<img border="0" name="IMGMANAGER" src="pic/mainmanager-manage.gif">
<a href="companylist.asp?page=<%=page-1%>&name=<%=name%>">
<img border="0" name="IMGPRE" src="pic/pre.gif"></a>
<a href="companylist.asp?page=<%=page+1%>&name=<%=name%>">
<img border="0" name="IMGNEXT" src="pic/next.gif"></a></p>
<hr size=1 color=#CC0066>
<div align="left"><font color=#CC0066>共 <b>
<% =allpage %>
</b>页,当前是第 <b>
<% =page %>
</b> 页 <hr size=1 color=#CC0066></div>
<%
i=1
do while not rs.eof
%>
<tr>
<td width="21">
<li>
</td>
<td width="100" nowrap><%=rs("gongname")%></td>
<td width="50" nowrap>
<a href="company.asp?id=<%=rs("gongid")%>"><img border="0" src="pic/more.gif" width="50" height="22"></a></td>
</tr>
<%
i=i+1
if i>iLen then exit do
rs.movenext
loop
rs.close
SET rs=nothing

%>
</table>


</font></font>


</body>

</html>
回复
antiking 2002-05-14
<%
dim chname
dat1=request("dat1")
dat2=request("dat2")
chname=request("chekedname")
name=trim(request("CName"))
passwd=trim(request("PASSWRD"))
gooto=trim(request("GooTo"))
If Request("Page")=Empty Then
Page=1
Else
Page=cint(Request("Page"))
End If
%>
<%
set conn=server.createobject("adodb.connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\majes.mdb"
conn.open connstr
set CustomerList= server.createobject("adodb.recordset")
sql= "select * from tbuser"
CustomerList.open sql,conn,3,2
if CustomerList.Recordcount=0 then
CustomerList.close
conn.close
response.write "目前没有记录……"
response.end
End If
CustomerList.PageSize = 20
If Not CustomerList.eof Then
CustomerList.AbsolutePage = PAGE
End If
pagecount=CustomerList.pagecount
I=1
do until CustomerList.EOF or I >= CustomerList.PageSize %>
<TR>
<TD width="200" align="center">
<p align="center"><% =CustomerList("id") %>
<TD width="200" align="center">
<p align="center"><% =CustomerList("username") %></TD>
<TD width="200" align="center">
<p align="center"><% =CustomerList("dat") %></TD>
<TD width="200" align="center">
<p align="center"><% =CustomerList("intime") %></TD>
<TD width="200" align="center">
<p align="center"><% =CustomerList("outtime") %></TD>
<TD width="500" align="center">
<p align="center"><% =CustomerList("mem") %></TD>
</TR>
<% CustomerList.movenext
I=I+1
loop
CustomerList.close
conn.close
%>
<%
If page>1 Then
Response.write "<a href=page.asp?page="&page-1&">上一页</a> "
End If
Response.write "页 <font face=Arial><b>"&pagecount&" / "
Response.write page &"</b></font> "
For j=1 to pagecount
IF J <> page THEN
response.write "<a href=page.asp?page="&j&">"&j&"</a> "
End If
Next
If page<pagecount Then
Response.write "<a href=page.asp?page="&page+1&">下一页</a> "
End If
'end select
%>
回复
dreamcast 2002-05-14
在前面 加了 rs.CursorLocation=3,出错提示提前一行

ADODB.Recordset (0x800A0E79)这是什么错误
连接语句用在其他操作上都可以
回复
gshope 2002-05-14
一定要rs.CursorLocation=3,否则rs.AbsolutePage 就报错!
回复
sduwjr 2002-05-14
不一定是那一行,浏览器的提示总是不准的。希望你能全局的考虑。
顺序的看,不用着急
回复
dreamcast 2002-05-14
<%

Sub ShowOnePage( rs, Page )
resoonse.write.........

rs.AbsolutePage = Page
For iPage = 1 To rs.PageSize
resoonse.write.........
rs.MoveNext
If rs.EOF Then Exit For
Next

End Sub

%>
浏览器老是提示
rs.AbsolutePage = Page那行出错,怎么解决啊?
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2002-05-14 11:02
社区公告
暂无公告