asp分页存储过程.docx

上传人:b****1 文档编号:2801691 上传时间:2023-05-04 格式:DOCX 页数:10 大小:17.78KB
下载 相关 举报
asp分页存储过程.docx_第1页
第1页 / 共10页
asp分页存储过程.docx_第2页
第2页 / 共10页
asp分页存储过程.docx_第3页
第3页 / 共10页
asp分页存储过程.docx_第4页
第4页 / 共10页
asp分页存储过程.docx_第5页
第5页 / 共10页
asp分页存储过程.docx_第6页
第6页 / 共10页
asp分页存储过程.docx_第7页
第7页 / 共10页
asp分页存储过程.docx_第8页
第8页 / 共10页
asp分页存储过程.docx_第9页
第9页 / 共10页
asp分页存储过程.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

asp分页存储过程.docx

《asp分页存储过程.docx》由会员分享,可在线阅读,更多相关《asp分页存储过程.docx(10页珍藏版)》请在冰点文库上搜索。

asp分页存储过程.docx

asp分页存储过程

asp分页存储过程

最简单使用方法(适用于任何数据表):

test.asp

--#include file="conn.asp"-->

--#include file="Page.asp"-->

<%

 Set My = New Page

 With My

 .SetConnstr=Connstr '数据库链接字符串

 .SetStrTable="users" '表名

 .SetStrText="id,username,type,names" '查询的字段

 .SetStrIndex="id" '主键

 rsArray=.GetRs() '返回数据,类型为数组

 End With

%>

<%

if IsArray(rsArray) then

 For i = 0 To UBound(rsArray, 2)

%>

 

 

 

 

 

<%

 next

end if

%>

 

 共<%= My.GetTotalNum %>条 每页<%= My.GetiPageSize %>条 共<%= My.GetTotalPage %>页 页码:

<%= My.GetFenYeJmp(false) %>

 

<%= rsArray(0, i) %><%= rsArray(1, i) %><%= rsArray(2, i) %>

 

 

还有很多功能可以拓展,复杂的查询、排序等,不一一演示了这个是使用到的asp类->Page.asp

 

'*******************************************************

'Page 分页类

'特点:

采用 not in 分页输出方法,需配合 sp_Page 存储过程使用,速度比较快

'输入参数 connstr:

数据库链接字符串 StrTable:

要查询的表 StrText:

要查询的字段 StrIndex:

索引字段

'可选参数:

(iPageSize:

每页记录数量 StrWhere:

条件语句 StrOrder:

排序字段 StrSc:

排序方法 ActionStr:

From提交的查询参数)

'输出参数 rsArray:

返回的记录集数组 GetTotalNum:

返回的总记录数 GetiPage:

当前页码 GetTotalPage:

总页数 GetiPageSize:

每页显示条数

'输出方法 GetFenYe():

分页 GetFenYeJmp(inForm):

带跳转的分页

'作者:

六月雨 QQ:

44569457 整理时间:

2008年9月27日

'*******************************************************

Class Page

 Private connstr '数据库链接字符串

 

 Private iPage '当前页码

 Private iPageSize '每页记录数量

 Private StrTable '要查询的表

 Private StrText '要查询的字段

 Private StrWhere '条件语句

 Private StrIndex '索引字段

 Private StrOrder '排序字段

 Private StrSc '排序方法

 

 Private ActionStr '翻页链接字符

 Private Rs_dbs '记录集名称

 Private cmd 'cmd对象名称

 Private rsArray '返回的记录集数组

 Private TotalNum '返回的总记录数

 

 Private Sub Class_Initialize() '初始化类

 iPageSize=10

 iPage=trim(Request("iPage"))

 ActionStr=""

 StrWhere=""

 StrOrder=""

 StrSc=""

 If (not IsNumeric(iPage)) Then

 iPage=1

 Else

 If iPage<1 then iPage=1

 If iPage>5000000 then iPage=1

 End If

 End Sub

 

 Private Sub Class_Terminate() '释放类

 set Rs_dbs=nothing

 End Sub

 

 Public Property Let SetConnstr(svalue) '取得:

数据库链接字符串

 connstr=Lcase(svalue)

 End Property

 

 Public Property Let SetiPageSize(svalue) '取得:

每页记录数量

 iPageSize=clng(svalue)

 End Property

 

 Public Property Let SetStrTable(svalue) '取得:

SQL表名

 StrTable=Lcase(svalue)

 End Property

 

 Public Property Let SetStrText(svalue) '取得:

SQL查询的字段

 StrText=Lcase(svalue)

 End Property

 

 Public Property Let SetStrWhere(svalue) '取得:

SQL条件字段

 StrWhere=Lcase(svalue)

 End Property

 

 Public Property Let SetStrIndex(svalue) '取得:

索引字段

 StrIndex=Lcase(svalue)

 End Property

 

 Public Property Let SetStrOrder(svalue) '取得:

排序字段

 StrOrder=Lcase(svalue)

 End Property

 

 Public Property Let SetStrSc(svalue) '取得:

排序方法

 StrSc=Lcase(svalue)

 End Property

 

 Public Property Let SetActionStr(svalue) '取得:

翻页链接字符

 ActionStr=Lcase(svalue)

 End Property

 

 Private Function MadeOrderBy() '方法:

组合Order By 语句

 dim TempStrOrder,TempStrSc,t

 if StrOrder<>"" and StrSc<>"" then

 TempStrOrder=split(StrOrder,",")

 TempStrSc=split(StrSc,",")

 if ubound(TempStrOrder)=ubound(TempStrSc) then

 for t=0 to ubound(TempStrOrder)

 if t=0 then

 MadeOrderBy=TempStrOrder(t)&" "&TempStrSc(t)

 else

 MadeOrderBy=MadeOrderBy&","&TempStrOrder(t)&" "&TempStrSc(t)

 end if

 next

 end if

 end if

 End Function

 

 Private Sub OpenRs() '方法:

获得记录集

 Set Rs_dbs=Server.CreateObject("ADODB.RECORDSET")

 Set cmd = Server.CreateObject("ADODB.Command")

 with cmd

 .ActiveConnection = connstr '数据库连接字串

 .CommandText = "sp_Page" '指定存储过程名

 .CommandType = 4 '表明这是一个存储过程

 .Prepared = true '要求将SQL命令先行编译

 .Parameters.append .CreateParameter("@iPage",3,1,4,iPage) '指定页数

 .Parameters.append .CreateParameter("@iPageSize",3,1,4,iPageSize) '每页记录数

 .Parameters.append .CreateParameter("@StrTable",200,1,200,StrTable) '分页时要查询的表名

 .Parameters.append .CreateParameter("@StrText",200,1,1000,StrText) '字段

 .Parameters.append .CreateParameter("@StrWhere",200,1,1000,StrWhere) '查询条件where 中的条件语句

 .Parameters.append .CreateParameter("@StrIndex",200,1,30,StrIndex) '索引值

 .Parameters.append .CreateParameter("@StrOrder",200,1,100,MadeOrderBy()) '排序的字段

 .Parameters.Append .CreateParameter("@StrTotals",3,2,10) '总页数output

 Set Rs_dbs = .Execute

 end with

 End Sub

 

 Public Property Get GetRs() '输出:

记录集(数组方式)

 call OpenRs()

 If not (Rs_dbs.eof and Rs_dbs.bof ) then

 GetRs = Rs_dbs.GetRows()

 End If

 Rs_dbs.close

 TotalNum = cmd(7)

 set cmd = nothing

 End Property

 

 Public Property Get GetTotalNum '输出:

总记录数

 GetTotalNum=TotalNum

 End Property

 

 Public Property Get GetTotalPage '输出:

总页数

 If (TotalNum mod iPageSize)<>0 Then

 GetTotalPage=(TotalNum\iPageSize)+1

 Else

 GetTotalPage=(TotalNum\iPageSize)

 End If

 End Property

 

 Public Property Get GetiPageSize '输出:

每页显示条数

 GetiPageSize=iPageSize

 End Property

 

 Public Property Get GetiPage '输出:

当前页码

 GetiPage=iPage

 End Property

 

 Private Function GetQueryUrl() '方法:

获得当前URL

 dim UrlFile,Query,Querys,i

 UrlFile= Request.Servervariables("URL")

 Query= Request.Servervariables("QUERY_STRING")

 Querys=split(Query,"&")

 For i=0 to ubound(Querys)

 if trim(Querys(i))<>"" then

 If trim(Querys(i))=replace(trim(Querys(i)),"iPage=","") then

 GetQueryUrl=GetQueryUrl&Querys(i)&"&"

 End If

 End If

 Next

 if ActionStr="" then

 GetQueryUrl=UrlFile&"?

"&GetQueryUrl

 else

 GetQueryUrl=UrlFile&"?

"&ActionStr&"&"&GetQueryUrl

 end if

 End Function

 

 Public Property Get GetFenYe() '输出:

分页

 If (iPage>=1) and (clng(iPage)<=clng(GetTotalPage)) then

 dim x,y,m,n,i,ActionUrL

 ActionUrL=GetQueryUrl()

 If iPage="" then iPage=1

 iPage=Clng(iPage)

 If TotalNum<>0 then

 x=TotalNum\iPageSize

 y=TotalNum mod iPageSize

 

 If y<>0 then x=x+1 '总页数

 if iPage>5 then

 If (iPage+5)<=x then

 n=iPage-4

 m=iPage+5

 Else

 n=iPage-4

 m=x

 End If

 Else

 n=1

 m=10

 End If

 

 If x<=10 then

 If x<>1 then

 if iPage<>1 then

 Response.Write" 上一页 "

 end if

 for i=1 to x

 if iPage=i then

 Response.Write(i)

 Else

 Response.Write" ["&i&"] "

 End If

 next

 if iPage<>x then

 Response.Write" 下一页 "

 end if

 End If

 Else

 If iPage>5 then

 Response.Write" [首页] "

 End If

 If iPage<>1 then

 Response.Write" 上一页 "

 end if

 for i=n to m

 if iPage>x then Exit For

 if iPage=i then

 Response.Write(i)

 Else

 Response.Write" ["&i&"] "

 End If

 next

 if iPage<>x then

 Response.Write" 下一页 "

 End If

 if (iPage+5)

 Response.Write" [尾页] "

 End If

 End If

 End If

 End If

 End Property

 

 Public Property Get GetFenYeJmp(inForm) '输出:

带跳转的分页

 if inForm then

 response.Write(GetFenYe()&"  ")

 response.Write("")

 else

 response.Write("")

 response.Write(GetFenYe()&" ")

 response.Write("")

 response.Write("

")

 end if

 End Property

End Class

 

 存储过程

 

CREATE PROCEDURE [dbo].[sp_Page]

@iPage int=1, --当前页码

@iPageSize int=10,--每页条数

@StrTable varchar(200),--查询的表

@StrText varchar(1000),--查询的字段

@StrWhere varchar(1000),--条件

@StrIndex varchar(30),--索引

@StrOrder varchar(100)='',--排序字段

@StrTotals int output --返回总条数

 AS

--定义变量

declare @SqlCount nvarchar(2000)

declare @Sql nvarchar(2000)

declare @TempOrder nvarchar(1000)

if @StrOrder<>""

 begin

 set @TempOrder=' order by '+@StrOrder

 end

else

 begin

 set @TempOrder=''

 end

--组合sql语句

if @iPage=1

 begin

 set @Sql='select top '+str(@iPageSize)+' '+@StrText+' from '+@StrTable+' where 1=1 '+@StrWhere+@TempOrder

 end

else

 begin

 set @Sql='select top '+str(@iPageSize)+' '+@StrText+' from '+@StrTable+' where '+@StrIndex+' not in (select top '+str(@iPageSize*(@iPage-1))+' '+@StrIndex+' from '+@StrTable+' where 1=1 '+@StrWhere+@TempOrder+') '+@StrWhere+@TempOrder

 end

set @SqlCount='select @StrTotals=isnull(count(*),10000) from '+@StrTable+' where 1=1 '+@StrWhere

--查询总记录数量

exec sp_executesql @SqlCount,N'@StrTotals int output',@StrTotals output

--执行sql语句返回

exec (@Sql)

GO

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2