日期:2012-09-24  浏览次数:20917 次

我的一个asp + sqlserver的分页程序:这个程序的特点就是指将当前页的纪录掉到页面上来。性能不错,而且不用存储过程,由于代码没有封装,所以很零散,要用到你的程序中,需要先简单读读。然后注意需要自己设置的地方的意思。有些是可以省略的。有些参数传递也是可以省略的。

        代码如下:

''''  塞北的雪  分页利器(sql server)  不用存储过程   -------------------------

'其中注释中有 ###的需要用户设置
'其中注释中有 参数传递 ** 的 说明要通过参数 传递。


'定义变量
dim tOption                  '查询条件
dim tOrder                   '排序字符串     
dim tOrderField              '排序字段        可通过参数获得:order_field
dim tOrderDirection          '排序方向        可通过参数获得:order_direction

dim tPageSize                '页大小
dim tTotalCount              '总记录数        可通过参数获得:t_count
dim tPageCount               '页数
dim tCurPage                 '当前页号        可通过参数获得:page

dim tTableName               '表或者视图名
dim tFieldAlias              '行号的别名
dim tFieldList               '查询的字段列表
dim tPageField               '用于分页的字段

dim r_count                  '查得的记录数


set rs=server.createobject("adodb.recordset")        '记录集对象

'排序处理
tOrderField=Request("order_field")                   '获得排序字段(参数传递 **)
tOrderDirection=Request("order_dir")                 '获得排序方向(参数传递 **)

if(tOrderField="") then tOrderField="item_code"       ' ### 设置默认排序字段
if(tOrderDirection="") then tOrderDirection="asc"     ' ### 设置默认排序方向

tOrder=" order by " & tOrderField & " " & tOrderDirection & " "   '生成排序字符串


'定义参数
tPageSize=find_rs_count        ' ### 设置页大小
tTableName="view_select1"      ' ### 设置与查询的表格或视图
tFieldList=" * "               ' ### 欲查询的字段列表
tPageField="item_code"         ' ### 设置一个主键或唯一索引的字段 ,用于分页计算


'页数处理
tCurPage=Request("page")             '获得当前页(参数传递 **)
tTotalCount=Request("t_count")       '获得总页数(参数传递 **)

if(tCurPage="") then tCurPage=1
if(cint(tCurPage)=0) then tCurPage=1
if(tPageCount="") then tPageCount =1
if(cint(tPageCount)=0) then tPageCount=1

' 构造查询条件,根据具体的程序,肯定不一样。但是最后的条件必须是“ where ??? ”
tOption=" issue_flag='Y'"                      ' ### 设置条件
if f_c<>"" then tOPtion= tOPtion & f_c         ' ### 设置条件

if trim(tOption)="" then