在ASP中大量数据的分页显示

redasp 2004-10-27 11:49:49
各位好!

我正在写一个ASP程序,但在实现数据分页显示时遇到了一个难题,当用RecordSet分页时,系统会将所有数据读入内存,这对于一个可能会有许多数据的ASP程序是不能容忍的.

我的这个问题的解决办法已经找了一段时间了,只找到了PHP的,用limit可用到ASP就不能用了,希望那位大虾帮一下我,感激不尽!
...全文
361 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueice2002 2005-03-25
  • 打赏
  • 举报
回复
N为每页显示的数 M为第几页
select top N * from tablename where id between (M-1)*N and M*N

速度确实快,但不适合排序
deiphi 2005-03-25
  • 打赏
  • 举报
回复
收藏
libao1983 2005-03-25
  • 打赏
  • 举报
回复
不要用Recordset分页
你可以这样
dim pagenum '页数
pagecount=20'每页20条数据
sql="select top " & pagecount & " * from table where id not in ( select top " & (pagenum-1)*pagecount & " id from table)" '其中id 为表table的主键

这样分也有一个缺点,就是越往后越慢,不过总的来说比Recordset快多了,还没有存储过程那么麻烦
hawk2004 2005-03-25
  • 打赏
  • 举报
回复
记得狼哥有个存储过程分页的

速度超快~~

你搜索一下~~或者问一下他:)~
masm_silly 2005-03-25
  • 打赏
  • 举报
回复
转个文章,楼主参考:

一个高效的数据分页的存储过程 可以轻松应付百万数据
CREATE PROCEDURE pageTest --用于翻页的测试
--需要把排序字段放在第一列
(
@FirstID nvarchar(20)=null, --当前页面里的第一条记录的排序字段的值
@LastID nvarchar(20)=null, --当前页面里的最后一条记录的排序字段的值
@isNext bit=null, --true 1 :下一页;false 0:上一页
@allCount int output, --返回总记录数
@pageSize int output, --返回一页的记录数
@CurPage int --页号(第几页)0:第一页;-1最后一页。
)
AS
if @CurPage=0
begin
--统计总记录数
select @allCount=count(ProductId) from Product_test

set @pageSize=10
--返回第一页的数据
select top 10
ProductId,
ProductName,
Introduction
from Product_test order by ProductId
end
else if @CurPage=-1
select * from
(select top 10 ProductId,
ProductName,
Introduction
from Product_test order by ProductId desc ) as aa
order by ProductId
else
begin
if @isNext=1
--翻到下一页
select top 10 ProductId,
ProductName,
Introduction
from Product_test where ProductId > @LastID order by ProductId


else
--翻到上一页
select * from
(select top 10 ProductId,
ProductName,
Introduction
from Product_test where ProductId < @FirstID order by ProductId desc) as bb order by ProductId
end

百万数据翻页就像100条数据一样!

istcn 2005-03-25
  • 打赏
  • 举报
回复
可以参考这个的存储过程
www.xx110.com/bbs

不知道错了吗

就是新乡110的 一个
china_hongyue 2005-03-25
  • 打赏
  • 举报
回复
select insert_time,
src_ip,
dest_ip,
operator
from (select insert_time,
src_ip,
dest_ip,
operator,
rownum as num
from (select insert_time,
src_ip,
dest_ip,
operator
from tbl_log
where insert_time >= 1 and insert_time <= 2 and
src_ip >= 1 and src_ip <= 2 and
dest_ip >= 1 and dest_ip <= 2 and operator = 1)
order by 1)
where num between 5 and 9
按照这个形式,自己写
超级大笨狼 2005-03-25
  • 打赏
  • 举报
回复
在SQL里面按F1查找sp_makewebtask
  • 打赏
  • 举报
回复
select top N * from tablename where id between (M-1)*N and M*N

这种方法 可以直接使用sql 也可以集成到sqlserver存储过程里

大数据量 这样做是很正确
它的弱点不是不好排序 而是如果排序的字段不是唯一值得话 就会数据混乱
所有最好制定一个唯一字段的ID

否则 就必须使用临时表了 搞起来就复杂了
kyn 2004-10-27
  • 打赏
  • 举报
回复
ASP也可以用top來做.
或是根据条件(如月份)做分段显示
dachangtui 2004-10-27
  • 打赏
  • 举报
回复
N为每页显示的数 M为第几页
select top N * from tablename where id between (M-1)*N and M*N

28,390

社区成员

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

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