asp.net 數(shù)據(jù)訪問層 存儲過程分頁語句
更新時間:2009年12月20日 02:13:45 作者:
在asp.net 網(wǎng)頁中如果在業(yè)務(wù)邏輯層分頁在使用PagedDataSource對象,但如果數(shù)據(jù)記錄過多,使用它會嚴重的損害應(yīng)用程序的性能.
所以最好在數(shù)據(jù)訪層分頁,如果這樣就要使用存儲過程來分頁.以下是以pubs 數(shù)據(jù)庫中的employee表為例來進行數(shù)據(jù)分頁的存儲過程,你可以參考它根據(jù)實際情況來創(chuàng)建自己的存儲過程.
注:@pageindex 數(shù)據(jù)頁的索引,@dataperpage 每頁的記錄數(shù)目,@howmanyrecords 用來獲取總的記錄數(shù).
create proc getdata @pageindex int,@dataperpage int,@howmanyrecords int output
as
declare @temptable table
(
rowindex int,
emp_id char(9),
fname varchar(20),
minit char(1),
lname varchar(30)
)
insert into @temptable
select row_number() over(order by emp_id) as rowindex,emp_id,fname,minit,lname
from employee
select @howmanyrecords=count(rowindex) from @temptable
select * from @temptable
where rowindex>(@pageindex-1)*@dataperpage
and rowindex<=@pageindex*@dataperpage
declare @howmanyrecords int
exec getdata 2,5,@howmanyrecords output
select @howmanyrecords
declare @x int, @y int, @z int
select @x = 1, @y = 2, @z=3
select @x,@y,@z
create proc getdata2 @pageindex int,@dataperpage int,@howmanyrecords int output
as
declare @temptable table
(
rowindex int,
emp_id char(9),
fname varchar(20),
minit char(1),
lname varchar(30)
)
insert into @temptable
select row_number() over(order by emp_id) as rowindex,emp_id,fname,minit,lname
from employee
select @howmanyrecords=count(rowindex) from @temptable
select * from @temptable
where rowindex>(@pageindex-1)*@dataperpage
and rowindex<=@pageindex*@dataperpage
其中Row_number 函數(shù)可以給檢索來的每條記錄按照排序來編號.
接下來你就可以在asp.net 網(wǎng)頁后臺代碼中調(diào)用該存儲過程,就可以獲取想要的數(shù)據(jù).
注:@pageindex 數(shù)據(jù)頁的索引,@dataperpage 每頁的記錄數(shù)目,@howmanyrecords 用來獲取總的記錄數(shù).
復(fù)制代碼 代碼如下:
create proc getdata @pageindex int,@dataperpage int,@howmanyrecords int output
as
declare @temptable table
(
rowindex int,
emp_id char(9),
fname varchar(20),
minit char(1),
lname varchar(30)
)
insert into @temptable
select row_number() over(order by emp_id) as rowindex,emp_id,fname,minit,lname
from employee
select @howmanyrecords=count(rowindex) from @temptable
select * from @temptable
where rowindex>(@pageindex-1)*@dataperpage
and rowindex<=@pageindex*@dataperpage
declare @howmanyrecords int
exec getdata 2,5,@howmanyrecords output
select @howmanyrecords
declare @x int, @y int, @z int
select @x = 1, @y = 2, @z=3
select @x,@y,@z
create proc getdata2 @pageindex int,@dataperpage int,@howmanyrecords int output
as
declare @temptable table
(
rowindex int,
emp_id char(9),
fname varchar(20),
minit char(1),
lname varchar(30)
)
insert into @temptable
select row_number() over(order by emp_id) as rowindex,emp_id,fname,minit,lname
from employee
select @howmanyrecords=count(rowindex) from @temptable
select * from @temptable
where rowindex>(@pageindex-1)*@dataperpage
and rowindex<=@pageindex*@dataperpage
其中Row_number 函數(shù)可以給檢索來的每條記錄按照排序來編號.
接下來你就可以在asp.net 網(wǎng)頁后臺代碼中調(diào)用該存儲過程,就可以獲取想要的數(shù)據(jù).
相關(guān)文章
C# 沒有動態(tài)的數(shù)組,可以用arraylist或list取代
C#里沒有動態(tài)的數(shù)組,只能用arraylist或list取代。2009-06-06c# .Net Core靜態(tài)文件服務(wù)器的新人入門教程
這篇文章主要給大家介紹了關(guān)于c# .Net Core靜態(tài)文件服務(wù)器的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧2018-07-07使用正則Regex來移除網(wǎng)頁的EnableViewState實現(xiàn)思路及代碼
創(chuàng)建好網(wǎng)頁時,什么都沒有寫,但運行時會發(fā)現(xiàn)源程序(View Source),下面一段,此刻,也許你會想起,在網(wǎng)頁有一個屬性EnableViewState,在某些時候我們并不需要它,接下來將介紹如何移除它,感興趣的朋友可以了解下啊2013-01-01VS2022?.NET5一鍵發(fā)布到遠程騰訊云IIS服務(wù)器的詳細步驟
這篇文章主要介紹了VS2022?.NET5一鍵發(fā)布到遠程騰訊云IIS服務(wù)器,首先需要添加服務(wù)器相關(guān)功能,文中通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04使CheckBoxList的Attributes屬性生效(修改微軟的一個bug)
使CheckBoxList的Attributes屬性生效(修改微軟的一個bug)...2007-08-08ASP.NET Core模仿中間件方式實現(xiàn)列表過濾功能
這篇文章介紹了ASP.NET Core模仿中間件方式實現(xiàn)列表過濾功能的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07