一、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
本文來自博客園,作者:TomLucas,轉載請注明原文鏈接:https://www.cnblogs.com/lucasDC/p/17233400.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/547374.html
標籤:其他
下一篇:MySQL如何正確查詢字串長度
