马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一、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
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |