高效分页 asp

<%

‘每页的记录数

dim pagesize

pagesize= "30"

‘读出总记录数,总页数,作者注

Dim TotalRecords,TotalPages

SQLstr="Select count(id) As RecordSum From table1"

Set Rs=conn.Execute(SQLstr,0,1)

TotalRecords=Rs("RecordSum")

if Int(TotalRecords/pagesize)=TotalRecords/pagesize then

TotalPages=TotalRecords/pagesize

else

TotalPages=Int(TotalRecords/pagesize)+1

end if

Rs.Close

Set Rs=Nothing

‘当前页码,作者注

dim page

page=Request("page")

if isnumeric(page)=false then

response.write "<SCRIPT language=JavaScript>alert(‘参数错误!‘);"

response.write "window.close();</SCRIPT>"

response.end

end if

If page="" or page<1 Then page=1

If page-TotalPages>0 Then page=TotalPages

page=int(page)

if page=1 then

sql="select top "&pagesize&" id,title,time from table1 order by time desc"

else

sql="select top "&pagesize&" id,title,time from table1 where time<(SELECT Min(time) FROM (SELECT TOP "&pagesize*(page-1)&" time FROM table1 ORDER BY time desc) AS T) order by time desc"

end if

Set rs = Server.CreateObject ("ADODB.Recordset")

rs.Open sql,conn,1,1

Do While Not rs.Eof

response.write "每条记录信息:"&rs("id")&"<br>"

rs.movenext

loop

rs.close

set rs=nothing

‘‘翻页代码省略……

%>

这是一种非常高效的分页算法。当数据表中的数据量成百上千万的时候,上面的这种分页算法的响应时间是非常短的,通常在几十毫秒之内。原理很简单,就是每次分页,我只取需要的几十条记录而已,使用SELECT TOP也正是基于这样的考虑。

高效分页 asp

时间: 2024-08-11 04:25:40

高效分页 asp的相关文章

高效分页

<%Option Explicit 'Response.Flush Dim BeginTime,EndTime BeginTime=Timer Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav DefRecordNum=5 '--------------获取相关参数---------- If Request("CursorBegin")="" Then CursorBegi

C#高效分页代码(不用存储过程)

首先创建一张表(要求ID自动编号): create table redheadedfile ( id int identity(1,1), filenames nvarchar(50), senduser nvarchar(50), primary key(id) ) 然后我们写入50万条记录: declare @i int set @i=1 while @i<=500000 begin insert into redheadedfile(filenames,senduser) values(&qu

ListView的高效分页

需要在DataSet中设定两个sql查询 1.根据参数查询指定页的数据 select *from ( select id,name,age,over(order by id)rownam from table where id>30 )t where t.rownam>@startRowIndex and t.rownam<[email protected][email protected] 这里注意!因为DataSet编辑器对over()函数不支持,所以要手动添加parameter设定

sql server 2000 单主键高效分页存储过程 (支持多字段排序)

sql server 2000 单主键高效分页存储过程 (支持多字段排序) Create PROC P_viewPage             /*              nzperfect [no_mIss] 高效通用分页存储过程(双向检索) 2007.5.7  QQ:34813284              敬告:适用于单一主键或存在唯一值列的表或视图              ps:Sql语句为8000字节,调用时请注意传入参数及sql总长度不要超过指定范围            

My Sql 高效分页

/* *普通分页 *在数据文件上偏移1000000查出10条 */ select * from zoldesk_92game_net_ecms_bj where classid=303 ORDER BY id ASC LIMIT 1000000,10 ; /* *高效分页 *1.在索引上查出起始索引 *2.从起始索引上查出10条 */ SELECT * from zoldesk_92game_net_ecms_bj WHERE id >= ( SELECT id FROM zoldesk_92g

php 高效分页

mysql.php 获取数据库中的记录,完全个人经验总结,仅供参考!<?php/***PHP+MYSQL数据库基本功能*http://blog.csdn.net/yown*/#############################################获取序列ID############################################function getSequence() {$sql = "update sequence set id=last_inser

【数据库】优化排序 &amp;&amp; 高效分页

例子: select <cols> from profiles where sex = 'M' order by rating  limit 10; 同时使用了order by,limit,如果没有索引会很慢.而sey的选择又很低,可以增加一些特殊的索引来做排序.例如,创建(sex,rating)索引. 即使有索引,如果用户需要翻页,并且翻页到比较靠后时查询也可能非常慢. 下面这个查询就通过order by 和limit偏移量的组合翻页到很靠后面的时候: mysql>select <

AJAX 分页 asp.net分页

原文链接:http://www.cnblogs.com/chenping-987123/archive/2011/02/14/1954640.html 查询功能是开发中最重要的一个功能,大量数据的显示,我们用的最多的就是分页. 在ASP.NET 中有很多数据展现的控件,比如Repeater.GridView,用的最多的GridView,它同时也自带了分页的功能.但是我们知道用GridView来显示数据,如果没有禁用ViewState,页面的大小会是非常的大的.而且平时我们点击首页,下一页,上一页

使用with as高效分页

一.WITH AS 含义     WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候,是为了让SQL语句的可读性更高些,也有可能是在UNION ALL的不同部分,作为提供数据的部分.特别对于UNION ALL比较有用.因为UNION ALL的每个部分可能相同,但是如果每个部分都去执行一遍的话,则成本太高,所以可以使用WITH AS短语,则只要执行一遍即可.如果WITH AS短语所定义