一、Entity Framework的Linq语句的分页写法:

 var datacount  = test.OrderBy(t => t.testID)
                    .Skip(pageSize * (pageIndex - 1))
                    .Take(pageSize).ToList();

二、SQL Server分页的SQL语句写法:

select
top (需要显示的条目数) *
from
DBTest
where TestID not in
(select top (需要剔除的条目数) TestID from DBTest)

三、SQL Server分页的存储过程写法:

第一种:

create proc proc_TestPage
@PageIndex  int --第几页
@PageSize  int  --每页显示的条数
@pageCount int output	--总的页数,因为需要显示页数,因此是个输出参数
as
declare @datacount int	--总数据条数
select @datacount=count(*) from DBTest--获得总数据条数值并赋给参数
set @pageCount=ceiling(1.0*@datacount/@pageSize)	--获得总页数,并赋给参数
select top(@PageSize) *  from DBTest where TestID not int (select top(@PageSize*(@PageIndex-1)) from DBTest)
select @PageCount=Count(*) from DBTest

第二种:

create proc P_Test	--创建存储过程P_Test
@pageSize int,	--每页数据条数
@pageIndex int,	--当前页数(页码)
@pageCount int output	--总的页数,因为需要显示页数,因此是个输出参数
as
declare @datacount int	--总数据条数
select @datacount=count(*) from DBTest --获得总数据条数值并赋给参数
set @pageCount=ceiling(1.0*@datacount/@pageSize)	--获得总页数,并赋给参数
--接下来是获得指定页数据
select * from
(select *,row_number() over(order by TestID ) as num from DBTest) as temp
where num between @pageSize*(@pageIndex-1)+1 and @pageSize*@pageIndex

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/lucasDC/p/17233400.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!