SQL分页存储过程
第一种方法:
- if exists(select * from sysobjects where name='usp_BookPage')
- drop procedure usp_BookPage
- go
- create procedure usp_BookPage
- @PageSize int,--每页显示多少
- @CurrentPage int--当前第多少页
- as
- --查询当前分页的数据
- select Top (@PageSize)BookId, BookName, BarCode, Author, PublisherId, PublishDate, BookCategory, UnitPrice, BookImage, BookCount, Remainder, BookPosition, RegTime
- from Books
- where BookId not in (select Top (@PageSize *(@CurrentPage -1)) BookId
- from Books order by RegTime asc )
- order by RegTime asc
- go
第二种方法
- if exists(select * from sysobjects where name='usp_BookPage')
- drop procedure usp_BookPage
- go
- create procedure usp_BookPage
- @PageSize int ,--每页显示多少页
- @CurrentPage int --当前第多少页
- as
- --查询分页
- select top (@PageSize) * from
- (select ROW_NUMBER() over (order by bookid) as rownumber,*
- from Books)A where rownumber >(@CurrentPage -1)*@PageSize
- go
c#中linq分页查询
- #region 数据分页
- int page = 0;
- if (Request.Form["page"]!=null && Request .Form["page"].Length >0)
- {
- page = Convert.ToInt32(Request.Form["page"]);
- }
- int pagesize = 10;
- if (Request .Form["pageSize"]!=null && Request .Form["pageSize"].Length >0)
- {
- pagesize = Convert.ToInt32(Request.Form["pageSize"]);
- }
- #endregion
- list_New = list_New.OrderBy(u => u.UserId).Skip((page - 1) * pagesize).Take(pagesize).ToList();