国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 數據訪問層 存儲過程分頁語句

2024-07-10 12:42:49
字體:
來源:轉載
供稿:網友
所以最好在數據訪層分頁,如果這樣就要使用存儲過程來分頁.以下是以pubs 數據庫中的employee表為例來進行數據分頁的存儲過程,你可以參考它根據實際情況來創建自己的存儲過程.

注:@pageindex 數據頁的索引,@dataperpage 每頁的記錄數目,@howmanyrecords 用來獲取總的記錄數.
代碼如下:
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 函數可以給檢索來的每條記錄按照排序來編號.

接下來你就可以在asp.net 網頁后臺代碼中調用該存儲過程,就可以獲取想要的數據.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 松滋市| 和龙市| 寿光市| 伊金霍洛旗| 根河市| 临颍县| 东阳市| 宜兰县| 体育| 赫章县| 凤冈县| 澄江县| 溧阳市| 大安市| 武定县| 加查县| 石棉县| 当阳市| 平昌县| 库伦旗| 芷江| 泸溪县| 琼海市| 盐池县| 黎平县| 玛纳斯县| 黄浦区| 通州市| 安乡县| 虹口区| 炎陵县| 安泽县| 淄博市| 佛学| 白城市| 黄平县| 光泽县| 吉林市| 牡丹江市| 出国| 寿宁县|