asp 存儲(chǔ)過程分頁代碼第2/2頁
更新時(shí)間:2008年12月13日 17:11:04 作者:
asp類加存儲(chǔ)過程分頁方法,查詢使用非常方便 new 一個(gè)類,加幾個(gè)參數(shù),就可以分頁顯示、多條件查詢、多個(gè)字段排序等功能、連表查詢等,一氣呵成!
還有很多功能可以拓展,復(fù)雜的查詢、排序等,不一一演示了
這個(gè)是使用到的asp類->Page.asp
復(fù)制代碼 代碼如下:
'*******************************************************
'Page 分頁類
'特點(diǎn):采用 not in 分頁輸出方法,需配合 sp_Page 存儲(chǔ)過程使用,速度比較快
'輸入?yún)?shù) connstr:數(shù)據(jù)庫鏈接字符串 StrTable:要查詢的表 StrText:要查詢的字段 StrIndex:索引字段
'可選參數(shù):(iPageSize:每頁記錄數(shù)量 StrWhere:條件語句 StrOrder:排序字段 StrSc:排序方法 ActionStr:From提交的查詢參數(shù))
'輸出參數(shù) rsArray:返回的記錄集數(shù)組 GetTotalNum:返回的總記錄數(shù) GetiPage:當(dāng)前頁碼 GetTotalPage:總頁數(shù) GetiPageSize:每頁顯示條數(shù)
'輸出方法 GetFenYe():分頁 GetFenYeJmp(inForm):帶跳轉(zhuǎn)的分頁
'作者:六月雨 QQ:44569457 整理時(shí)間:2008年9月27日
'*******************************************************
Class Page
Private connstr '數(shù)據(jù)庫鏈接字符串
Private iPage '當(dāng)前頁碼
Private iPageSize '每頁記錄數(shù)量
Private StrTable '要查詢的表
Private StrText '要查詢的字段
Private StrWhere '條件語句
Private StrIndex '索引字段
Private StrOrder '排序字段
Private StrSc '排序方法
Private ActionStr '翻頁鏈接字符
Private Rs_dbs '記錄集名稱
Private cmd 'cmd對(duì)象名稱
Private rsArray '返回的記錄集數(shù)組
Private TotalNum '返回的總記錄數(shù)
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) '取得:數(shù)據(jù)庫鏈接字符串
connstr=Lcase(svalue)
End Property
Public Property Let SetiPageSize(svalue) '取得:每頁記錄數(shù)量
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 '數(shù)據(jù)庫連接字串
.CommandText = "sp_Page" '指定存儲(chǔ)過程名
.CommandType = 4 '表明這是一個(gè)存儲(chǔ)過程
.Prepared = true '要求將SQL命令先行編譯
.Parameters.append .CreateParameter("@iPage",3,1,4,iPage) '指定頁數(shù)
.Parameters.append .CreateParameter("@iPageSize",3,1,4,iPageSize) '每頁記錄數(shù)
.Parameters.append .CreateParameter("@StrTable",200,1,200,StrTable) '分頁時(shí)要查詢的表名
.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) '總頁數(shù)output
Set Rs_dbs = .Execute
end with
End Sub
Public Property Get GetRs() '輸出:記錄集(數(shù)組方式)
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 '輸出:總記錄數(shù)
GetTotalNum=TotalNum
End Property
Public Property Get GetTotalPage '輸出:總頁數(shù)
If (TotalNum mod iPageSize)<>0 Then
GetTotalPage=(TotalNum\iPageSize)+1
Else
GetTotalPage=(TotalNum\iPageSize)
End If
End Property
Public Property Get GetiPageSize '輸出:每頁顯示條數(shù)
GetiPageSize=iPageSize
End Property
Public Property Get GetiPage '輸出:當(dāng)前頁碼
GetiPage=iPage
End Property
Private Function GetQueryUrl() '方法:獲得當(dāng)前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 '總頁數(shù)
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" <a href="&ActionUrL&"iPage="&(iPage-1)&">上一頁</a> "
end if
for i=1 to x
if iPage=i then
Response.Write(i)
Else
Response.Write" <a href="&ActionUrL&"iPage="&i&">["&i&"]</a> "
End If
next
if iPage<>x then
Response.Write" <a href="&ActionUrL&"iPage="&(iPage+1)&">下一頁</a> "
end if
End If
Else
If iPage>5 then
Response.Write" <a href="&ActionUrL&"iPage=1>[首頁]</a> "
End If
If iPage<>1 then
Response.Write" <a href="&ActionUrL&"iPage="&(iPage-1)&">上一頁</a> "
end if
for i=n to m
if iPage>x then Exit For
if iPage=i then
Response.Write(i)
Else
Response.Write" <a href="&ActionUrL&"iPage="&i&">["&i&"]</a> "
End If
next
if iPage<>x then
Response.Write" <a href="&ActionUrL&"iPage="&(iPage+1)&">下一頁</a> "
End If
if (iPage+5)<x then
Response.Write" <a href="&ActionUrL&"iPage="&x&">[尾頁]</a> "
End If
End If
End If
End If
End Property
Public Property Get GetFenYeJmp(inForm) '輸出:帶跳轉(zhuǎn)的分頁
if inForm then
response.Write(GetFenYe()&" <input name='iPage' type='text' value="&iPage&" id='iPage' size='3'> ")
response.Write("<input type='submit' name='Submit' value='轉(zhuǎn)'>")
else
response.Write("<form name='Jmp' method='post' action="&GetQueryUrl()&">")
response.Write(GetFenYe()&" <input name='iPage' type='text' value="&iPage&" id='iPage' size='3'>")
response.Write("<input type='submit' name='Submit' value='轉(zhuǎn)'>")
response.Write("</form>")
end if
End Property
End Class
存儲(chǔ)過程
復(fù)制代碼 代碼如下:
begin
set @Sql='select top '+str(@iPageSize)+' '+@StrText+' from '+@StrTable+' where '+@StrIndex+' not in (select top '+str(@iPageSize*(@iPaCREATE PROCEDURE [dbo].[sp_Page]
@iPage int=1, --當(dāng)前頁碼
@iPageSize int=10,--每頁條數(shù)
@StrTable varchar(200),--查詢的表
@StrText varchar(1000),--查詢的字段
@StrWhere varchar(1000),--條件
@StrIndex varchar(30),--索引
@StrOrder varchar(100)='',--排序字段
@StrTotals int output --返回總條數(shù)
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
ge-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
--查詢總記錄數(shù)量
exec sp_executesql @SqlCount,N'@StrTotals int output',@StrTotals output
--執(zhí)行sql語句返回
exec (@Sql)
GO
相關(guān)文章
ASP中實(shí)現(xiàn)的URLEncode、URLDecode自定義函數(shù)
這篇文章主要介紹了ASP中實(shí)現(xiàn)的URLEncode、URLDecode自定義函數(shù),和ASP自帶的server.urlencode是不一樣的哦,需要的朋友可以參考下2014-07-07捕捉并保存ASP運(yùn)行錯(cuò)誤的函數(shù)代碼
捕捉并保存ASP運(yùn)行錯(cuò)誤的函數(shù)代碼,需要獲取asp代碼運(yùn)行錯(cuò)誤的朋友可以參考下2012-03-03ASP網(wǎng)站出現(xiàn) msxml3.dll 錯(cuò)誤 80072ee7 錯(cuò)誤的解決方法
這兩天接到通知,說公司的一個(gè)網(wǎng)站訪問不了,經(jīng)訪問發(fā)現(xiàn)頁面提示如下錯(cuò)誤2011-08-08SQLServer ADODB.Recordset 錯(cuò)誤“800a0e78”,對(duì)象關(guān)閉時(shí),不允許操作
今天在幫一個(gè)客戶維護(hù)網(wǎng)站的時(shí)候,運(yùn)行asp提示ADODB.Recordset 錯(cuò)誤“800a0e78”,對(duì)象關(guān)閉時(shí),不允許操作,原來是asp與sqlserver的連接出問題導(dǎo)致2014-07-07.NET?Core?分布式任務(wù)調(diào)度ScheduleMaster詳解
這篇文章主要介紹了分布式任務(wù)調(diào)度ScheduleMaster,集中任務(wù)調(diào)度系統(tǒng),最簡(jiǎn)單的理解ScheduleMaster,就是對(duì)不同的系統(tǒng)里面的調(diào)度任務(wù)做統(tǒng)一管理的框架,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05