在ASP对MSSQL数据操作中怎么样实现分页?[[[[急]]]
dim rscon,page,all
set rscon=server.createobject("adodb.recordset")
strsql="select * from jtc_answer order by id desc"
set rscon = objconnection.Execute (strSql)
rscon.pagesize=1
page=rscon.pagecount
all=rscon.recordcount
rscon.absolutepage=abpage
rscon.absolutepage=1
这样执行的时候总是出错,难道Execute方法就不能设置分页吗?
错误如下:
ADODB.Recordset (0x800A0CB3)
当前记录集不支持书签。这可能是提供程序或选定的游标类型的限制。
请各位大虾帮忙!
问题点数:100、回复次数:14Top
1 楼ccmoon(IzuaL)回复于 2003-09-02 16:57:00 得分 0
set rscon = objconnection.Execute (strSql)
改成
rscon.Open strSql, objconnection,1,1Top
2 楼511214(小少)回复于 2003-09-02 17:00:56 得分 0
rscon.Open strSql, objconnection,3,1Top
3 楼511214(小少)回复于 2003-09-02 17:02:22 得分 0
rscon.Open strSql, objconnection,3,1Top
4 楼511214(小少)回复于 2003-09-02 17:04:14 得分 100
附:
Recordset对象Open方法的CursorType参数表示将以什么样的游标类型启动数据,包括adOpenForwardOnly、adOpenKeyset、adOpenDynamic及adOpenStatic,分述如下:
--------------------------------------------------------------
常数 常数值 说明
-------------------------------------------------------------
adOpenForwardOnly 0 缺省值,启动一个只能向前移动的游标(Forward Only)。
adOpenKeyset 1 启动一个Keyset类型的游标。
adOpenDynamic 2 启动一个Dynamic类型的游标。
adOpenStatic 3 启动一个Static类型的游标。
-------------------------------------------------------------
以上几个游标类型将直接影响到Recordset对象所有的属性和方法,以下列表说明他们之间的区别。
-------------------------------------------------------------
Recordset属性 adOpenForwardOnly adOpenKeyset adOpenDynamic adOpenStatic
-------------------------------------------------------------
AbsolutePage 不支持 不支持 可读写 可读写
AbsolutePosition 不支持 不支持 可读写 可读写
ActiveConnection 可读写 可读写 可读写 可读写
BOF 只读 只读 只读 只读
Bookmark 不支持 不支持 可读写 可读写
CacheSize 可读写 可读写 可读写 可读写
CursorLocation 可读写 可读写 可读写 可读写
CursorType 可读写 可读写 可读写 可读写
EditMode 只读 只读 只读 只读
EOF 只读 只读 只读 只读
Filter 可读写 可读写 可读写 可读写
LockType 可读写 可读写 可读写 可读写
MarshalOptions 可读写 可读写 可读写 可读写
MaxRecords 可读写 可读写 可读写 可读写
PageCount 不支持 不支持 只读 只读
PageSize 可读写 可读写 可读写 可读写
RecordCount 不支持 不支持 只读 只读
Source 可读写 可读写 可读写 可读写
State 只读 只读 只读 只读
Status 只读 只读 只读 只读
AddNew 支持 支持 支持 支持
CancelBatch 支持 支持 支持 支持
CancelUpdate 支持 支持 支持 支持
Clone 不支持 不支持
Close 支持 支持 支持 支持
Delete 支持 支持 支持 支持
GetRows 支持 支持 支持 支持
Move 不支持 支持 支持 支持
MoveFirst 支持 支持 支持 支持
MoveLast 不支持 支持 支持 支持
MoveNext 支持 支持 支持 支持
MovePrevious 不支持 支持 支持 支持
NextRecordset 支持 支持 支持 支持
Open 支持 支持 支持 支持
Requery 支持 支持 支持 支持
Resync 不支持 不支持 支持 支持
Supports 支持 支持 支持 支持
Update 支持 支持 支持 支持
UpdateBatch 支持 支持 支持 支持
--------------------------------------------------------------
其中NextRecordset方法并不适用于Microsoft Access数据库。
LockType
Recordset对象Open方法的LockType参数表示要采用的Lock类型,如果忽略这个参数,那么系统会以Recordset对象的LockType属性为预设值。LockType参数包含adLockReadOnly、adLockPrssimistic、adLockOptimistic及adLockBatchOptimistic等,分述如下:
-------------------------------------------------------------
常数 常数值 说明
--------------------------------------------------------------
adLockReadOnly 1 缺省值,Recordset对象以只读方式启动,无法运行AddNew、Update及Delete等方法
adLockPrssimistic 2 当数据源正在更新时,系统会暂时锁住其他用户的动作,以保持数据一致性。
adLockOptimistic 3 当数据源正在更新时,系统并不会锁住其他用户的动作,其他用户可以对数据进行增、删、改的操作。
adLockBatchOptimistic 4 当数据源正在更新时,其他用户必须将CursorLocation属性改为adUdeClientBatch才能对数据进行增、删、改的操作。Top
5 楼pcking(我爱.net)回复于 2003-09-02 17:05:28 得分 0
多谢楼上的帮助!!!Top
6 楼511214(小少)回复于 2003-09-02 17:06:57 得分 0
给你一个分面的程序
PgSz=20 '!设定开关,指定每一页所显示的帖子数目,默认为20帖一页
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM message order by ID DESC"
'!查询所有帖子,并按帖子的ID倒序排列
Conn.Open "bbs"
RS.open sql,Conn,1,1
If RS.RecordCount=0 then
response.write "< P>< center>对不起,数据库中没有相关信息!< /center>< /P>"
else
RS.PageSize = Cint(PgSz) '!设定PageSize属性的值
Total=INT(RS.recordcount / PgSz * -1)*-1 '!计算可显示页面的总数
PageNo=Request("pageno")
if PageNo="" Then
PageNo = 1
else
PageNo=PageNo+1
PageNo=PageNo-1
end if
ScrollAction = Request("ScrollAction")
if ScrollAction = " 上一页 " Then
PageNo=PageNo-1
end if
if ScrollAction = " 下一页 " Then
PageNo=PageNo+1
end if
if PageNo < 1 Then
PageNo = 1
end if
n=1
RS.AbsolutePage = PageNo
Response.Write "< CENTER>"
position=RS.PageSize*PageNo
pagebegin=position-RS.PageSize+1
if position < RS.RecordCount then
pagend=position
else
pagend= RS.RecordCount
end if
Response.Write "< P>< font color='!Navy'!>< B>数据库查询结果:< /B>"
Response.Write "(共有"&RS.RecordCount &"条符合条件的信息,显示"&pagebegin&"-"&pagend&")< /font>< /p>"
Response.Write "< TABLE WIDTH=600 BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR=#FFFFFF>"
Response.Write "< TR BGCOLOR=#5FB5E2>< FONT SIZE=2>< TD>< B>主题< /B>< /TD>< TD>< B>用户< /B>< /TD>< TD>< B>Email< /B>< /TD>< TD>< B>发布日期< /B>< /TD>< /FONT>< TR BGCOLOR=#FFFFFF>"
Do while not (RS is nothing)
RowCount = RS.PageSize
Do While Not RS.EOF and rowcount > 0
If n=1 then
Response.Write "< TR BGCOLOR=#FFFFFF>"
ELSE
Response.Write "< TR BGCOLOR=#EEEEEE>"
End If
n=1-n %>
< TD>< span style="font-size:9pt">< A href='!view.asp?key=< % =RS("ID")%>'!>< % =RS("subject")%>< /A>< /span>< /td>
< TD>< span style="font-size:9pt">< % =RS("name")%>< /A>< /span>< /td>
< TD>< span style="font-size:9pt">< a href="mailto:< % =RS("email")%>">< % =RS("email")%>< /a>< /span> < /TD>
< TD>< span style="font-size:9pt">< % =RS("postdate")%>< /span> < /td>
< /TR>
< %
RowCount = RowCount - 1
RS.MoveNext
Loop
set RS = RS.NextRecordSet
Loop
Conn.Close
set rs = nothing
set Conn = nothing
%>
< /TABLE>
< FORM METHOD=GET ACTION="list.asp">
< INPUT TYPE="HIDDEN" NAME="pageno" VALUE="< % =PageNo %>">
< %
if PageNo > 1 Then
response.write "< INPUT TYPE=SUBMIT NAME='!ScrollAction'! VALUE='! 上一页 '!>"
end if
if RowCount = 0 and PageNo < >Total then
response.write "< INPUT TYPE=SUBMIT NAME='!ScrollAction'! VALUE='! 下一页 '!>"
end if
response.write "< /FORM>"
End if
%>
Top
7 楼511214(小少)回复于 2003-09-02 17:07:48 得分 0
共同进步^-^Top
8 楼yangyanli(乌托邦主·蛤蟆)回复于 2003-09-02 17:14:07 得分 0
收藏。Top
9 楼lions911(--Administrator--)回复于 2003-09-02 17:16:58 得分 0
给你一个参考程序,用来 分页:
<%
diaryperpage=15 '设置每页显示的页数
dim totaldiary,Currentpage,totalpages,i
set rs=server.CreateObject("ADODB.RecordSet")
rs.Source="select * from news,bigclass where bigclass.bigclassid=news.bigclassid order by ID desc"
rs.Open rs.Source,conn,1,1
%>
<table width="80%%" border="0" cellspacing="1" align=center>
<tr>
<td width="592" height="14"><b><font size="4">[修改记录]</font></b></td>
</tr>
</table>
<TABLE>
<TR>
<TD></TD>
</TR>
</TABLE>
<%if not rs.eof then
rs.Movefirst
rs.pagesize=diaryperpage '每页显示多少条记录
if trim(request("page"))<>"" then
currentpage=clng(request("page"))
if currentpage>rs.pagecount then
currentpage=rs.pagecount
end if
else
currentpage=1
end if
totaldiary=rs.recordcount
if currentpage<>1 then
if(currentpage-1)*diaryperpage<totaldiary then
rs.move(currentpage-1)*diaryperpage
dim bookmark
bookmark=rs.bookmark
end if
end if
if (totaldiary mod diaryperpage)=0 then
totalpages=totaldiary\diaryperpage
else
totalpages=totaldiary\diaryperpage+1
end if
position=RS.PageSize*currentpage
pagebegin=position-RS.PageSize+1
pagebegin=30-30+1=1
if position < RS.RecordCount then
pagend=position
else
pagend= RS.RecordCount
end if
i=0
color=1
%>
<table width="80%" border="0" cellspacing="1" align="center" cellpadding="2" bgcolor="#E7E3E7">
<%
do while not rs.eof and i<diaryperpage
%>
<tr>
<td class="chinese" bgcolor="#FFFFFF" align="right">
<%
if color mod 2 <>0 then
%>
<table width="99%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor=#E6E6E6>
<%else%>
<table width="99%" border="0" cellspacing="0" cellpadding="0" align="center">
<%end if%>
<form method='POST' action='ModifyNews2.asp?id=<%=rs("id")%>&bigclassid=<%=rs("bigclassid")%>'>
<input type=hidden name=ID value=<%= rs("ID")%>>
<tr><td width=74% ><FONT COLOR="#000000"> </FONT><FONT COLOR='#CC0000'>[<%=rs("bigclassname")%>]</FONT> <font color=225588><A HREF="../readnews.asp?id=<%=rs("id")%>" target=_blank><%=rs("title")%></A> </font></a></td>
<td width="23%" align=right ><input type=submit value="修改" style="border-style: double; border-color: #efefef"></td>
</form>
</tr>
</table>
</td>
</tr>
<%
i=i+1
color=color+1
rs.movenext
loop
else
If rs.EOF And rs.BOF Then%>
<tr>
<td height="30" class="chinese" align="center" bgcolor="#E7E3E7">目前还没有记录!</td>
</tr>
<%end if
end if%>
</table>
</td></tr></table>
<table width="80%" border="0" cellspacing="0" align="center" cellpadding="0" bgcolor="white">
<form name="form1" method="post" action="modifynews1.asp">
<tr>
<td><BR></td>
</tr>
<tr>
<td align="right" class="diaryhead">显示[<%=pagebegin%>-<%=pagend%>]条 <%=currentpage%>/<%=totalpages%>页,<%=totaldiary%>条记录/<%=diaryperpage%>篇每页.
<%
i=1
'dy10=false
showye=totalpages
'if showye>10 then
'dy10=true
'showye=10
'end if
for i=1 to showye
if i=currentpage then
%>
<%=i%>
<%else%>
<a href="modifynews1.asp?page=<%=i%>">[<%=i%>]</a>
<%end if
next
if totalpages>currentpage then
if request("page")="" then
page=1
else
page=request("page")+1
end if%>
<a href="modifynews1.asp?page=<%=page%>" title="下一页">>>></a>
<%end if%>
<%'if not dy10 then%>
<input type="text" name="page" class="textarea" size="1" value="<%=currentpage%>">
<input type="submit" name="Submit" value="Go" class="button">
<%'end if%>
</td>
</tr>
</form>
</table>
<TABLE align="center" border=0 width="80%">
<TR>
<TD align="right">
<form name="form2" method="post" action="modifynews1.asp">
显示[<%=pagebegin%>-<%=pagend%>]条 <%=currentpage%>/<%=totalpages%>页,<%=totaldiary%>条记录/<%=diaryperpage%>篇每页.
<%
k=currentPage
n=rs.pagecount
if k<>1 then
response.write "[<b>"+"<a href='modifynews1.asp?page=1'>首页</a></b>] "
response.write "[<b>"+"<a href='modifynews1.asp?page="+cstr(k-1)+"'>上一页</a></b>] "
else
Response.Write "[首页][上一页]"
end if
if k<>n then
response.write "[<b>"+"<a href='modifynews1.asp?page="+cstr(k+1)+"'>下一页</a></b>] "
response.write "[<b>"+"<a href='modifynews1.asp?page="+cstr(n)+"'>尾页</a></b>] "
else
Response.Write "[下一页][尾页] "
end if
Response.Write"<input type='text' name='page' class='textarea' size='1' value="¤tpage&">"
Response.Write"<input type='submit' name='Submit' value='Go' class='button'>"
%>
</form></TD>
</TR>
</TABLE>
<%
rs.close
set rs=nothing
%>
Top
10 楼zanpo(谁说我不在乎)回复于 2003-09-02 17:18:07 得分 0
在大型的ASP项目中,很多的页面都涉及到翻页功能。如果每个页面都写一个翻页的程序的话,这样的工作即降低了工作效率,也不利于工程的模块化,不能使代码重用。因此,把翻页这样的功能模块化是很有必要的。
设计方法:
1、调用该模块时,只需要传递记录集和每页显示的记录的条数;
2、可以点击链接进行翻页,也可以直接输入页码,回车后翻页;
3、不要考虑文件名,程序的每次翻页都能在当前页面。
想清楚了上面3个问题,我们的公共翻页模块就可以动手了。
<%
+++++++++++++++++++++++++++++++++++++
◆模块名称: 公共翻页模块
◆文 件 名: TurnPage.asp
◆传入参数: Rs_tmp (记录集), PageSize (每页显示的记录条数)
◆输 出: 记录集翻页显示功能
+++++++++++++++++++++++++++++++++++++
Sub TurnPage(ByRef Rs_tmp,PageSize) Rs_tmp 记录集 ; PageSize 每页显示的记录条数;
Dim TotalPage 总页数
Dim PageNo 当前显示的是第几页
Dim RecordCount 总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
取得当前的文件名称,使翻页的链接指向当前文件;
fileName = Mid(fileName,postion)
%>
<table border=0 width=100%>
<tr>
<td align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页
当前第<font color=#ff3333><%=PageNo%></font>页</td>
<td align="right">
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首页|前页|后页|末页"
Else%>
<a href="<%=fileName%>?PageNo=1">首页|</a>
<%If PageNo - 1 = 0 Then
Response.Write "前页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write "后页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
<%End If%>
<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
<%End If%></td>
<td width=95>转到第
<%If TotalPage = 1 Then%>
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3">
<%Else%>
<input type=text name=PageNo size=3 value="" title=请输入页号,然后回车>
<%End If%>页
</td>
</tr>
</table>
<%End Sub%>
当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。
调用方法:
1、在程序开始或要使用翻页的地方包含翻页模块文件;
2、定义变量:RowCount,每页显示的记录条数
3、调用翻页过程:Call TurnPage(记录集,RowCount)
4、在Do While 循环输出记录集的条件中加上" RowCount > 0 " 条件
5、在循环结束 "Loop前" 加上: RowCount = RowCount - 1
-----------------------------------------------------
调用范例:
文件名:News.asp
<%
Dim Conn,Rs_News
Set Conn = server.CreateObject("ADODB.CONNECTION")
Conn.Open "cpm","cpm","cpm"
Dim Sql
Sql = "Select * from News"
Set Rs_News = Server.CreateObject("ADODB.RECORDSET")
Rs_News.Open Sql,Conn,1,3 获取的记录集
公共翻页模块开始%>
<!--#include file=../Public/TurnPage.asp-->
<%
Dim RowCount
RowCount = 10 每页显示的记录条数
Call TurnPage(Rs_News,RowCount)
公共翻页模块结束%>
<table width=100%>
<tr>
<td>新闻编号</td>
<td>新闻标题</td>
<td>发布日期</td>
<tr>
<%
If Not Rs_News.eof
Do while Not Rs_News.eof and RowCount>0
%>
<tr>
<td><%=Rs_News("ID")%></td>
<td><%=Rs_News("Name")%></td>
<td><%=Rs_News("Date")%></td>
<tr>
<%
RowCount = RowCount - 1
Rs_News.MoveNext
Loop
End If
%>
修正:
<%
If Not Rs_News.eof then
Do while Not Rs_News.eof and RowCount>0
%>
而那个公共模块缺<form>,改后:
<%
Sub TurnPage(ByRef Rs_tmp,PageSize) Rs_tmp 记录集 ; PageSize 每页显示的记录条数;
Dim TotalPage 总页数
Dim PageNo 当前显示的是第几页
Dim RecordCount 总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
fileName = Mid(fileName,postion)
%>
<table border=0 width=100%>
<tr>
<td width="258" align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页
当前第<font color=#ff3333><%=PageNo%></font>页 总共<%=RecordCount%>条 </td>
<td width="308" align="right"> <div align="center">
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首页|前页|后页|末页"
Else%>
<a href="<%=fileName%>?PageNo=1">首页|</a>
<%If PageNo - 1 = 0 Then
Response.Write "前页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write "后页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
<%End If%>
<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
<%End If%>
</div></td>
<td width=189><form name="form1" method="post" action=""> 转到第 <% If TotalPage = 1 Then%>
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3">
<input type="submit" name="Submit" value="Go" disabled style="background:#d3d3d3">
<%Else%>
<input type=text name=PageNo size=3 >
<input type="submit" name="Submit" value="Go">
<%End If%>
</form>
页
</td>
</tr>
</table>
<%End Sub%>Top
11 楼WQ771211(SyanSea)回复于 2003-09-02 19:10:47 得分 0
请注意一个最关键的问题——效率问题
执行SELECT * FROM 表这样的SQL是最恐怖的,可以把WEB服务器拖垮
正确的写法是:
假设每页20条记录,要显示第51页
SELECT TOP 20 * FROM 表 WHERE 主键 NOT IN (SELECT TOP 1000 主键 FROM 表 ORDER BY 某个字段) ORDER BY 某个字段
上面的“20”,“1000”可以根据更改Top
12 楼bluezwt(蓝色天涯)回复于 2003-09-02 19:16:32 得分 0
以前刚学asp时写的一个很简单的分页类,试试
'=============================================================
' T_Pages
' 属性:Z_FileName:所要传递参数的页面,默认为当前页
' Z_TableHeader: 要显示的每个栏位的表头,用"|"隔开
' Z_SqlStr : RecordSet的查询sql语句
' Z_Conn: Connection的连接串
' Z_PerRecordCount : 每页显示的记录条数
'=============================================================
Class T_Pages
Public Z_FileName
Public Z_TableHeader
Public Z_SqlStr,Z_ConnStr
Public Z_PerRecordCount
Private z_rs1,z_conn1,Z_CurPage
Public z_outstr
Private Sub Class_Initialize()
Dim str
str = Request.ServerVariables("URL")
Z_FileName = Right(str,Len(str)-1)
Z_PerRecordCount = 20
Z_IndexPage = 0
End Sub
Public Sub ShowPage
Dim strOut,strValue
Dim iTotalCount,iPageCount,iEnd
Dim strHeader
On Error Resume Next
Set z_conn1 = Server.CreateObject("ADODB.Connection")
Set z_rs1 = Server.CreateObject("ADODB.RecordSet")
z_conn1.Open Z_ConnStr
If Err Then
Err.Clear
Response.Write("连接数据库错误!")
Response.End
End IF
z_rs1.CursorType = 0
z_rs1.CursorLocation = 3
z_rs1.LockType = 1
z_rs1.Open Z_SqlStr,Z_ConnStr
iTotalCount = z_rs1.RecordCount
If iTotalCount > 0 Then
If iTotalCount Mod Z_PerRecordCount = 0 Then
iPageCount = iTotalCount / Z_PerRecordCount
Else
iPageCount = Int( iTotalCount / Z_PerRecordCount)+1
End If
If IsEmpty(Request("Page")) Or Not IsNumeric(Trim(Request("page"))) Then
Z_CurPage = 1
Else
Z_CurPage = CInt(Trim(Request("page")))
End If
If Z_CurPage < 1 Then Z_CurPage =1
If Z_CurPage > iPageCount Then Z_CurPage = iPageCount
'显示分页按钮
strOut = "<form name= form1 method=post action="+Z_FileName+"><Table Width=100% border=0><tr>"
If Z_CurPage < 2 Then
strOut = strOut + "<td width = 10% > 首页 </td>"
strOut = strOut + "<td width = 10% > 上页 </td> "
Else
strOut = strOut + "<td width = 10% > <a href =" +Z_FileName+"?page=1>首页<td>"
strOut = strOut + "<td width = 10% > <a href =" +Z_FileName+"?page="+CStr(Z_CurPage-1)+"> 上页 </td> "
End If
If Z_CurPage +1 > iPageCount Then
strOut = strOut + "<td width = 10% > 下页 </td>"
strOut = strOut + "<td width = 10% > 末页 </td> "
Else
strOut = strOut + "<td width = 10% > <a href = "+Z_FileName+"?page="+Cstr(Z_CurPage+1)+">下页<td>"
strOut = strOut + "<td width = 10% > <a href = "+Z_FileName+"?page="+CStr(iPageCount)+"> 末页 <td> "
End If
strOut = strOut + "<td width = 50% >共"+CStr(iTotalCount)+"条记录 第 "+CStr(Z_Curpage)+"/"+Cstr(iPageCount)+" 页 <td>"
strOut = strOut + "<td width=10% ><Input type=Edit Name=page Value="+Cstr(Z_CurPage)+" Style="+""""+"width:50px"+""""+">"+_
"<Input Type = Submit value=Go name=Button1></td>"
strOut = strOUt + "</tr></table></form>"
Z_OutStr = strOut
'Response.Write strOut
'显示数据
strOut = "<Table Width =100% border =0 bgcolor=#000000 cellspacing=1 cellpadding=3>"+ "<tr bgcolor=#EFEFFF>"
'显示每个栏位的表头
strHeader = Split(z_TableHeader,"|")
For j=0 To z_rs1.Fields.Count-1
If UBound(strHeader) >= z_rs1.Fields.Count-1 Then
strOut = strOut + "<td align=center><b>"+strHeader(j)+"</b></td>"
Else
strOut = strOut + "<td align=center><b>"+z_rs1.Fields(j).Name+"</b></td>"
End If
Next
strOut = strOut +"</tr>"
z_rs1.Move((Z_CurPage-1)*Z_PerRecordCount)
If Z_CurPage*Z_PerRecordCount-iTotalCount<=0 Then
iEnd = Z_PerRecordCount
Else
iEnd= Z_PerRecordCount -Z_CurPage*Z_PerRecordCount+ iTotalCount
End IF
For i = 1 To iEnd
strOut =strOut + "<tr bgcolor=#EFEFFF>"
For j=0 To z_rs1.Fields.Count - 1
strValue = Trim(CStr(z_rs1.Fields(j).Value))
If Trim(strValue)="" Then strValue=" "
strOut = strOut +"<td>"+strValue+"</td>"
Next
strOut = strOut +"</tr>"
z_rs1.MoveNext
Next
strOut = strOut +"</table>"
Z_OutStr = Z_OUtStr +strOut
Else
str = "找不到数据."
Z_OutStr= str
End If
Response.Write Z_OUtStr
End Sub
Private Sub Class_Terminate()
Set z_rs1 = Nothing
Set z_conn1= Nothing
End Sub
End Class
'测试分页显示类
'Dim p
'Set p=New T_Pages
'p.Z_ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=ID;Initial Catalog=DB;Data Source=server"
'p.Z_SqlStr = "Select a,b,c From Table1"
'p.Z_PerRecordCount = 5
'p.Z_TableHeader = "dd|dd|dd"
'p.ShowPage
%>Top
13 楼WQ771211(SyanSea)回复于 2003-09-02 19:21:59 得分 0
用"select count(主键) As RecCount from 表" 就可以获取表的记录数
set rs=cn.Execute("select count(主键) As RecCount from 表")
rs.Fields("RecCount")就是记录总数Top
14 楼shutdown(netpower)回复于 2003-09-02 20:03:30 得分 0
翻页,一种落后的网页编程技术。
上面所有的例子,都有一个通病,服务器取回了所有的数据行(rs.recordcount),不要攻击我,自己使用SQL跟踪看看就知道了。
使用select count()就相当于查询数据库两次,特别是有条件的时候,负载很大,是最差的办法了。
所以终极解决方案是虚拟滚动(Virtual List)加异步读取加二进制存储过程。
过几天,有时间,好好写一篇颠覆ASP编程的帖子。
现在有兴趣的可以去看看www.zydsoft.com的e商2003的在线演示,注意是2003不是2000。Top
15 楼WQ771211(SyanSea)回复于 2003-09-03 10:21:30 得分 0
密切关注。。。Top



