一:row_number方法分页
string Sql="select * from (select row_number() over (order by created) as row_number,* from contents) as T where T.row_number>"+(pagenumber-1)*pagesize+"and T.row_number<="+pagenumber*pagesize:
其中contents为表名,pagenumber为当前显示的页号,pagesize为每页显示的数据条数!
=====================================================================================
二:Sql自定义方式分页
declare@pageIndexint
declare@startRowIndexint
declare@maximumRowsint
set@pageIndex=5
set@startRowIndex=0
set@maximumRows=1000
set@startRowIndex=(@pageIndex-1)*@maximumRows+1
select ProductID,ProductName,AuthorNames,ManufacturerName,RowRank
from (
select ProductID,ProductName,AuthorNames,ManufacturerName,row_number() over(orderby ProductID) as RowRank
from Products
) as ProductsWithRowNumbers
where RowRank >=@startRowIndex
and RowRank < (@startRowIndex+@maximumRows)
declare@startRowIndexint
declare@maximumRowsint
set@pageIndex=5
set@startRowIndex=0
set@maximumRows=1000
set@startRowIndex=(@pageIndex-1)*@maximumRows+1
select ProductID,ProductName,AuthorNames,ManufacturerName,RowRank
from (
select ProductID,ProductName,AuthorNames,ManufacturerName,row_number() over(orderby ProductID) as RowRank
from Products
) as ProductsWithRowNumbers
where RowRank >=@startRowIndex
and RowRank < (@startRowIndex+@maximumRows)