你参考一下这个存储过程: CREATE procedure GetInfomation (@pagesize int,@pageindex int,@docount bit) AS set nocount on if(@docount=1) select count(InfoID) from Infomation where InfoCategoryID = @InfoCategoryID else begin declare @indextable table(InfoID int identity(1,1),nid int) declare @PageLowerBound int declare @PageUpperBound int set @PageLowerBound=(@pageindex-1)*@pagesize set @PageUpperBound=@PageLowerBound+@pagesize set rowcount @PageUpperBound insert into @indextable(nid) select InfoID from Infomation order by Date desc select O.InfoID,O.Writer,O.title,O.Date from Infomation O,@indextable t where O.InfoID=t.nid and t.InfoID>@PageLowerBound and t.InfoID<=@PageUpperBound order by t.InfoID end set nocount off GO
IF EXISTS (SELECT name FROM sysobjects WHERE name = N'test' AND type = 'P') DROP PROCEDURE test GO create proc test @startcount int =null, --开始的行数 @stopcount int=null --结束的行数 as --可以用table变量(SQL Server 2000),table变量是存储在内存中的 --如果你的服务器内存不多的话,可以考虑用临时表,临时表使用硬盘存储结果, --临时表需要手工释放对象,而table变量在存储过程结束后自动释放。 declare @tempTable table ( id int identity(1,1) primary key, customerid varchar(30), companyname varchar(100), contactname varchar(100) ) --SET ROWCOUNT语句对优化性能很关键,它告诉SQL Server进行限制要插入的数据 set rowcount @stopcount ----假如要查 2,30之间的记录,就先 插入前30条记录 insert @tempTable(customerid,companyname,contactname) select customerid,companyname,contactname from customers--按自增的列排序 用@startcount 限定到比@startcount的记录 返回 select id,customerid,companyname,contactname from @tempTable where id>=@startcount order by id --执行存储过程 返回 2-4行之间的记录 exec test 2,4
分页程序,10万数据在50毫秒之内 <% '****************************************************************** '** 本程序名:"无限流"分页程序 '****************************************************************** '** '** 【作者的话】 '** '** 分页程序无疑是许多网络程序功能中一个比较麻烦的东西,事实上现在 '** 为止绝大部分人还是在使用传统的分页方法(Rs.PageSize=xx),而了解 '** 数据库操作的人都知道,这种传统方式有个弊端:第一次打开页面时, '** 它会预读所有的记录集,这当在数据大的时候,这将是致命的,而且接 '** 下来的翻页速度也会非常慢,很占用资源。对于十万数量级以上的数据 '** 库这种传统分页方式已经显得非常无力,更别说百万级了(根本没法操 '** 作)。基于这种原因,促使我做了本程序。 '** '** 【程序功能】 '** '** 针对大型的数据库进行分页操作,理想的可操作的数据记录量在200万 '** 以内(Max Level版将无数量限制,且无论数据库多大,翻页速度都是 '** 不变),这是Million Level版分页程序在赛扬1G、内存512、win2k环 '** 境下的测试数据: '** '** SQLserver 2k + 10万条记录 + 每页显示20条: '** 平均翻页速度:45ms '** SQLserver 2k + 100万条记录 + 每页显示20条: '** 平均翻页速度:350ms '** '** '** 【分页原理】 '** '** 本程序不再使用Rs.PageSize的方式分页,连接数据库的游标类型 '** 也不是使用conn,1,x,而是conn,0,1,这应是最快的游标类型了,不要 '** 以为这样会使程序变得复杂,相反,程序非常简单,如果你看不明白, '** 应该是我的编程风格你不习惯,而非程序复杂。 '** "无限流"分页的中心是:每页只读出需要显示的记录,不再象传统 '** 分页程序预读全部的数据,这正在本程序最大的优点--占用资源少,同 '** 理速度也得到非常大的提升,特别在数据量越大的时候,它的速度优势 '** 越明显(100万记录才350ms左右)。 '** 当程序执行后,使用CurcorBegin和CurcorEnd记录显示的第一条记 '** 录和最后一条记录的ID值,作为下一次翻页的标记,然后利用Top xx取 '** 出需要的数据显示,同时又再对ID值进行记录。 '** '** 【结 言】 '** '** 本程序为共享版,提供给各程序爱好者研究使用,若要转载、散播、修 '** 改或作其他用途,请尊重作者的辛劳,注明出处。 '** 如果本程序中有错漏、非最优化等缺点,www.csdn.net的Web开发/ '** ASP栏目中发表讨论,为了中国软件事业的发展,请不要固步自封:) '** '******************************************************************** Option Explicit 'Response.Flush Dim BeginTime,EndTime BeginTime=Timer Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav DefRecordNum=20 '--------------获取相关参数---------- If Request("CursorBegin")="" Then CursorBegin=0 Else CursorBegin=Request("CursorBegin") If Request("CursorEnd")="" Then CursorEnd=0 Else CursorEnd=Request("CursorEnd") If Request("CurPageNum")<>"" Then CurPageNum=CLng(Request("CurPageNum")) If CurPageNum<=0 Then CurPageNum=1 Else CurPageNum=1 End If hav=Request("hav") If hav="" Then hav="next" '----------------End----------------- '------------显示翻页内容函数-------- Function TurnPageFS(DispRecordNum) Dim n While Not(Rs.Eof) And n<DispRecordNum n=n+1 Response.Write "<tr>"&_ "<td bgcolor='efefef'>"&Rs(0)&"</td>"&_ "<td bgcolor='efefef'>"&Rs(1)&"</td>"&_ "<td bgcolor='efefef'>"&Rs(2)&"</td>"&_ "<td bgcolor='efefef'>"&Rs(3)&"</td>"&_ "<td bgcolor='efefef'>"&Rs(4)&"</td>"&_ "<td bgcolor='efefef'>"&Rs(5)&"</td>"&_ "</tr>" If n=1 Then CursorBegin=Rs(0) If n=DefRecordNum Or Rs.Eof Then CursorEnd=Rs(0) Rs.MoveNext Wend End Function '-------------连接数据库------------- Set conn=Server.CreateObject("Adodb.Connection") 'SQLstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("mldata.mdb") SQLstr="Driver={SQL Server};server=arbiter;uid=arbiter;pwd=123456;database=mldata" conn.Open SQLstr '---------统计总记录数/总页数--------- '-PS:推荐使用count(ID),ID为自动编号且索引,否则速度有可能大打折扣 '-PS:此统计是本程序中最耗资源的一部分,如果取消这段程序,速度会快上10倍左右 Dim TotalRecords,TotalPages SQLstr="Select count(ID) As RecordSum From ABC" Set Rs=conn.Execute(SQLstr,0,1) TotalRecords=Rs("RecordSum") TotalPages=Abs(Int(TotalRecords/DefRecordNum*(-1))) Rs.Close Set Rs=Nothing '--------根据hav选择相应的SQL字串----- Select Case(hav) Case "back" CursorEnd=CursorBegin SQLstr="Select Top "&DefRecordNum&" ID,Title,FileName,K,ImgSize,NameSon From ABC Where ID<"&CursorBegin&_ " And ID In (Select Top "&DefRecordNum&" ID From ABC Where ID<"&CursorBegin&" Order by ID DESC) Order by ID" Case "next" SQLstr="Select Top "&DefRecordNum&" ID,Title,FileName,K,ImgSize,NameSon From ABC Where ID>"&CursorEnd&_ " Order by ID" End Select Set Rs=conn.Execute(SQLstr,0,1) %> <html> <head> <title>"无限流"分页程序 作者:Arbiter</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css">td,br,div,p,body {font-size:12px}</style> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"> <table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE"> <tr align="center"> <td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"页 总记录数:"&TotalRecords%></td> <td>首页</a> 上一页</a> 下一页</a> </td> </tr> </table> <table width="100%" border="1" cellspacing="0" cellpadding="3" bgcolor="#CCCCCC"> <tr> <td>ID</td> <td>Title</td> <td>FileName</td> <td>大小</td> <td>尺寸</td> <td>类别</td> </tr> <% TurnPageFS(DefRecordNum) Rs.Close Set Rs=Nothing conn.Close Set conn=Nothing %> </table> <table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE"> <tr align="center"> <td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"页 总记录数:"&TotalRecords%></td> <td>首页</a> 上一页</a> 下一页</a> </td> </tr> </table> <% EndTime=Timer Response.Write "<br>程序执行时间:"&(EndTime-BeginTime)*1000&"毫秒" Response.Write " 第一条记录的ID值(CursorBegin)="&CursorBegin&" " Response.Write "最后一条记录的ID值(CursorEnd)="&CursorEnd&"<br><br>" %> <script language="javascript"> function turnpage(func){ var CurPageNum=<%=CurPageNum%>; //取得当前页码 var CursorBegin=<%=CursorBegin%>; //取得第一个显示的记录的ID值 var CursorEnd=<%=CursorEnd%>; //取得最后一个显示的记录的ID值 var TotalPages=<%=TotalPages%>; //取得页面总数 var BackUrl='mllist.asp?CurPageNum='+(CurPageNum-1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=back'; var NextUrl='mllist.asp?CurPageNum='+(CurPageNum+1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=next'; if(CurPageNum<=1 && func=='back'){ location.href='#'; }else if(CurPageNum>=TotalPages && func=='next'){ location.href='#'; }else if(func=='back'){ location.href=BackUrl; }else if(func='next'){ location.href=NextUrl; } } </script> </body> </html>
分页存储过程: if exists(select * from sysobjects where ID = object_id("up_TopicList")) drop proc up_TopicList gocreate proc up_TopicList @a_ForumID int , @a_intDays int , @a_intPageNo int , @a_intPageSize tinyint as declare @m_intRecordNumber int declare @m_intStartRecord int select @m_intRecordNumber = @a_intPageSize * @a_intPageNo select @m_intStartRecord = @a_intPageSize * (@a_intPageNo - 1) + 1if @a_intDays = 0 --如果不限定天数 begin /*求符合条件记录数*/ select "RecordCount" = count(*) from BBS where Layer=1 and ForumID = @a_ForumID /*输出纪录*/ /*首先定义可滚动光标*/ set rowcount @m_intRecordNumber declare m_curTemp Scroll cursor for select a.ID ,a.Title , d.UserName , a.FaceID , 'ContentSize' = datalength(a.Content) , 'TotalChilds' = (select sum(TotalChilds) from BBS as b where a.RootID = b.RootID) , 'LastReplyTime' = (select max(PostTime) from BBS as c where a.RootID = c.RootID) from BBS as a join BBSUser as d on a.UserID = d.ID where Layer=1 and ForumID = @a_ForumID order by RootID desc , Layer , PostTime open m_curTemp fetch absolute @m_intStartRecord from m_curTemp while @@fetch_status = 0 fetch next from m_curTempset rowcount 0 /*清场*/ CLOSE m_curTemp DEALLOCATE m_curTemp end else --如果限定天数 begin /*求符合条件记录数*/ select "RecordCount" = count(*) from BBS where Layer=1 and ForumID = @a_ForumID and dateadd(day , @a_intDays , PostTime) > getdate() /*输出纪录*/ /*首先定义可滚动光标*/ set rowcount @m_intRecordNumber declare m_curTemp Scroll cursor for select a.ID ,a.Title , d.UserName , a.FaceID , 'ContentSize' = datalength(a.Content) , 'TotalChilds' = (select sum(TotalChilds) from BBS as b where a.RootID = b.RootID) , 'LastReplyTime' = (select max(PostTime) from BBS as c where a.RootID = c.RootID) from BBS as a join BBSUser as d on a.UserID = d.ID where Layer=1 and ForumID = @a_ForumID and dateadd(day , @a_intDays , PostTime) > getdate() order by RootID desc , Layer , PostTime open m_curTemp fetch absolute @m_intStartRecord from m_curTemp while @@fetch_status = 0 fetch next from m_curTempset rowcount 0 /*清场*/ CLOSE m_curTemp DEALLOCATE m_curTemp end go
2。在客户端,点击了页号以后,这个页号传递到数据库端,根据这个页号,从临时表中换算应当取出来的记录。
to:cdshelf(cdshelf)可以给出具体例子吗?
page 为第几页
思路是这样,不知是否可行
CREATE procedure GetInfomation (@pagesize int,@pageindex int,@docount bit) AS
set nocount on
if(@docount=1)
select count(InfoID) from Infomation where InfoCategoryID = @InfoCategoryID
else
begin
declare @indextable table(InfoID int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select InfoID from Infomation order by Date desc
select O.InfoID,O.Writer,O.title,O.Date from Infomation O,@indextable t where O.InfoID=t.nid
and t.InfoID>@PageLowerBound and t.InfoID<=@PageUpperBound order by t.InfoID
end
set nocount off
GO
FROM sysobjects
WHERE name = N'test'
AND type = 'P')
DROP PROCEDURE test
GO
create proc test
@startcount int =null, --开始的行数
@stopcount int=null --结束的行数
as
--可以用table变量(SQL Server 2000),table变量是存储在内存中的
--如果你的服务器内存不多的话,可以考虑用临时表,临时表使用硬盘存储结果,
--临时表需要手工释放对象,而table变量在存储过程结束后自动释放。
declare @tempTable table
(
id int identity(1,1) primary key,
customerid varchar(30),
companyname varchar(100),
contactname varchar(100)
)
--SET ROWCOUNT语句对优化性能很关键,它告诉SQL Server进行限制要插入的数据
set rowcount @stopcount
----假如要查 2,30之间的记录,就先 插入前30条记录
insert @tempTable(customerid,companyname,contactname)
select customerid,companyname,contactname from customers--按自增的列排序 用@startcount 限定到比@startcount的记录 返回
select id,customerid,companyname,contactname from @tempTable where id>=@startcount order by id
--执行存储过程 返回 2-4行之间的记录
exec test 2,4
为什么这里的人经常来句"用存取过程"?我目前采用的的方法和cnlamar(无中生有)说的差不多
至于hansonboy(良)说的方法,我测试过,速度多的时候特别差
<%
'******************************************************************
'** 本程序名:"无限流"分页程序
'******************************************************************
'**
'** 【作者的话】
'**
'** 分页程序无疑是许多网络程序功能中一个比较麻烦的东西,事实上现在
'** 为止绝大部分人还是在使用传统的分页方法(Rs.PageSize=xx),而了解
'** 数据库操作的人都知道,这种传统方式有个弊端:第一次打开页面时,
'** 它会预读所有的记录集,这当在数据大的时候,这将是致命的,而且接
'** 下来的翻页速度也会非常慢,很占用资源。对于十万数量级以上的数据
'** 库这种传统分页方式已经显得非常无力,更别说百万级了(根本没法操
'** 作)。基于这种原因,促使我做了本程序。
'**
'** 【程序功能】
'**
'** 针对大型的数据库进行分页操作,理想的可操作的数据记录量在200万
'** 以内(Max Level版将无数量限制,且无论数据库多大,翻页速度都是
'** 不变),这是Million Level版分页程序在赛扬1G、内存512、win2k环
'** 境下的测试数据:
'**
'** SQLserver 2k + 10万条记录 + 每页显示20条:
'** 平均翻页速度:45ms
'** SQLserver 2k + 100万条记录 + 每页显示20条:
'** 平均翻页速度:350ms
'**
'**
'** 【分页原理】
'**
'** 本程序不再使用Rs.PageSize的方式分页,连接数据库的游标类型
'** 也不是使用conn,1,x,而是conn,0,1,这应是最快的游标类型了,不要
'** 以为这样会使程序变得复杂,相反,程序非常简单,如果你看不明白,
'** 应该是我的编程风格你不习惯,而非程序复杂。
'** "无限流"分页的中心是:每页只读出需要显示的记录,不再象传统
'** 分页程序预读全部的数据,这正在本程序最大的优点--占用资源少,同
'** 理速度也得到非常大的提升,特别在数据量越大的时候,它的速度优势
'** 越明显(100万记录才350ms左右)。
'** 当程序执行后,使用CurcorBegin和CurcorEnd记录显示的第一条记
'** 录和最后一条记录的ID值,作为下一次翻页的标记,然后利用Top xx取
'** 出需要的数据显示,同时又再对ID值进行记录。
'**
'** 【结 言】
'**
'** 本程序为共享版,提供给各程序爱好者研究使用,若要转载、散播、修
'** 改或作其他用途,请尊重作者的辛劳,注明出处。
'** 如果本程序中有错漏、非最优化等缺点,www.csdn.net的Web开发/
'** ASP栏目中发表讨论,为了中国软件事业的发展,请不要固步自封:)
'**
'********************************************************************
Option Explicit
'Response.Flush
Dim BeginTime,EndTime
BeginTime=Timer
Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav
DefRecordNum=20
'--------------获取相关参数----------
If Request("CursorBegin")="" Then CursorBegin=0 Else CursorBegin=Request("CursorBegin")
If Request("CursorEnd")="" Then CursorEnd=0 Else CursorEnd=Request("CursorEnd")
If Request("CurPageNum")<>"" Then
CurPageNum=CLng(Request("CurPageNum"))
If CurPageNum<=0 Then CurPageNum=1
Else
CurPageNum=1
End If
hav=Request("hav")
If hav="" Then hav="next"
'----------------End-----------------
'------------显示翻页内容函数--------
Function TurnPageFS(DispRecordNum)
Dim n
While Not(Rs.Eof) And n<DispRecordNum
n=n+1
Response.Write "<tr>"&_
"<td bgcolor='efefef'>"&Rs(0)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(1)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(2)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(3)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(4)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(5)&"</td>"&_
"</tr>"
If n=1 Then CursorBegin=Rs(0)
If n=DefRecordNum Or Rs.Eof Then CursorEnd=Rs(0)
Rs.MoveNext
Wend
End Function
'-------------连接数据库-------------
Set conn=Server.CreateObject("Adodb.Connection")
'SQLstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("mldata.mdb")
SQLstr="Driver={SQL Server};server=arbiter;uid=arbiter;pwd=123456;database=mldata"
conn.Open SQLstr
'---------统计总记录数/总页数---------
'-PS:推荐使用count(ID),ID为自动编号且索引,否则速度有可能大打折扣
'-PS:此统计是本程序中最耗资源的一部分,如果取消这段程序,速度会快上10倍左右
Dim TotalRecords,TotalPages
SQLstr="Select count(ID) As RecordSum From ABC"
Set Rs=conn.Execute(SQLstr,0,1)
TotalRecords=Rs("RecordSum")
TotalPages=Abs(Int(TotalRecords/DefRecordNum*(-1)))
Rs.Close
Set Rs=Nothing
'--------根据hav选择相应的SQL字串-----
Select Case(hav)
Case "back"
CursorEnd=CursorBegin
SQLstr="Select Top "&DefRecordNum&" ID,Title,FileName,K,ImgSize,NameSon From ABC Where ID<"&CursorBegin&_
" And ID In (Select Top "&DefRecordNum&" ID From ABC Where ID<"&CursorBegin&" Order by ID DESC) Order by ID"
Case "next"
SQLstr="Select Top "&DefRecordNum&" ID,Title,FileName,K,ImgSize,NameSon From ABC Where ID>"&CursorEnd&_
" Order by ID"
End Select
Set Rs=conn.Execute(SQLstr,0,1)
%>
<html>
<head>
<title>"无限流"分页程序 作者:Arbiter</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">td,br,div,p,body {font-size:12px}</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE">
<tr align="center">
<td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"页 总记录数:"&TotalRecords%></td>
<td>首页</a> 上一页</a>
下一页</a> </td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="3" bgcolor="#CCCCCC">
<tr>
<td>ID</td>
<td>Title</td>
<td>FileName</td>
<td>大小</td>
<td>尺寸</td>
<td>类别</td>
</tr>
<%
TurnPageFS(DefRecordNum)
Rs.Close
Set Rs=Nothing
conn.Close
Set conn=Nothing
%>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE">
<tr align="center">
<td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"页 总记录数:"&TotalRecords%></td>
<td>首页</a> 上一页</a>
下一页</a> </td>
</tr>
</table>
<%
EndTime=Timer
Response.Write "<br>程序执行时间:"&(EndTime-BeginTime)*1000&"毫秒"
Response.Write " 第一条记录的ID值(CursorBegin)="&CursorBegin&" "
Response.Write "最后一条记录的ID值(CursorEnd)="&CursorEnd&"<br><br>"
%>
<script language="javascript">
function turnpage(func){
var CurPageNum=<%=CurPageNum%>; //取得当前页码
var CursorBegin=<%=CursorBegin%>; //取得第一个显示的记录的ID值
var CursorEnd=<%=CursorEnd%>; //取得最后一个显示的记录的ID值
var TotalPages=<%=TotalPages%>; //取得页面总数
var BackUrl='mllist.asp?CurPageNum='+(CurPageNum-1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=back';
var NextUrl='mllist.asp?CurPageNum='+(CurPageNum+1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=next';
if(CurPageNum<=1 && func=='back'){
location.href='#';
}else if(CurPageNum>=TotalPages && func=='next'){
location.href='#';
}else if(func=='back'){
location.href=BackUrl;
}else if(func='next'){
location.href=NextUrl;
}
}
</script>
</body>
</html>
if exists(select * from sysobjects where ID = object_id("up_TopicList"))
drop proc up_TopicList
gocreate proc up_TopicList
@a_ForumID int , @a_intDays int , @a_intPageNo int , @a_intPageSize tinyint
as
declare @m_intRecordNumber int
declare @m_intStartRecord int
select @m_intRecordNumber = @a_intPageSize * @a_intPageNo
select @m_intStartRecord = @a_intPageSize * (@a_intPageNo - 1) + 1if @a_intDays = 0 --如果不限定天数
begin
/*求符合条件记录数*/
select "RecordCount" = count(*)
from BBS where Layer=1 and ForumID = @a_ForumID /*输出纪录*/
/*首先定义可滚动光标*/
set rowcount @m_intRecordNumber
declare m_curTemp Scroll cursor
for
select a.ID ,a.Title , d.UserName , a.FaceID ,
'ContentSize' = datalength(a.Content) ,
'TotalChilds' = (select sum(TotalChilds)
from BBS as b
where a.RootID = b.RootID) ,
'LastReplyTime' = (select max(PostTime)
from BBS as c
where a.RootID = c.RootID)
from BBS as a
join BBSUser as d on a.UserID = d.ID
where Layer=1 and ForumID = @a_ForumID
order by RootID desc , Layer , PostTime
open m_curTemp
fetch absolute @m_intStartRecord from m_curTemp
while @@fetch_status = 0
fetch next from m_curTempset rowcount 0
/*清场*/
CLOSE m_curTemp
DEALLOCATE m_curTemp
end else --如果限定天数 begin
/*求符合条件记录数*/
select "RecordCount" = count(*)
from BBS where Layer=1 and ForumID = @a_ForumID
and dateadd(day , @a_intDays , PostTime) > getdate() /*输出纪录*/
/*首先定义可滚动光标*/
set rowcount @m_intRecordNumber
declare m_curTemp Scroll cursor
for
select a.ID ,a.Title , d.UserName , a.FaceID ,
'ContentSize' = datalength(a.Content) ,
'TotalChilds' = (select sum(TotalChilds)
from BBS as b
where a.RootID = b.RootID) ,
'LastReplyTime' = (select max(PostTime)
from BBS as c
where a.RootID = c.RootID)
from BBS as a
join BBSUser as d on a.UserID = d.ID
where Layer=1 and ForumID = @a_ForumID
and dateadd(day , @a_intDays , PostTime) > getdate()
order by RootID desc , Layer , PostTime
open m_curTemp
fetch absolute @m_intStartRecord from m_curTemp
while @@fetch_status = 0
fetch next from m_curTempset rowcount 0
/*清场*/
CLOSE m_curTemp
DEALLOCATE m_curTemp
end
go
adapter.Fill(result,currentIndex,PageSize,TableName);
不知道哪位高手能给我指教一下这种方法的内部机理?
分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url直接访问除首页外的其它页面、数据量大时分页性能明显下降等,而且有时候我们需要对DataList和Repeater甚至自定义数据绑定控件进行分页,手工书写分页代码不但技术难度大、任务繁琐而且代码重用率极低,因此分页已成为许多ASP.NET程序员最头疼的问题之一。AspNetPager针对ASP.NET分页控件的不足,提出了与众不同的分页方案,即分页与数据显示功能的完全独立,因此使该控件适合于任何需要分页的数据绑定控件。