C#分页 无法显示余页 ?
我分页的sql 语句是
select top pagesize field from [tablename] where id
> all(select top pageindex id from [tablename] order by id asc) order by id asc
问题就是,如果一页显示10条记录,一共有77条记录,那么最后一页的7条记录取不出来,不知道是什么问题??
------解决方案--------------------CREATE PROCEDURE northwind_OrdersPaged( @PageIndex int, @PageSize int)ASBEGINDECLARE @PageLowerBound intDECLARE @PageUpperBound intDECLARE @RowsToReturn int
-- First set the rowcountSET @RowsToReturn = @PageSize * (@PageIndex + 1)SET ROWCOUNT @RowsToReturn-- Set the page boundsSET @PageLowerBound = @PageSize * @PageIndexSET @PageUpperBound = @PageLowerBound + @PageSize + 1
-- Create a temp table to store the select resultsCREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, OrderID int)-- Insert into the temp tableINSERT INTO #PageIndex (OrderID)
SELECT OrderIDFROM OrdersORDER BY OrderID DESC-- Return total countSELECT COUNT(OrderID) FROM Orders-- Return paged resultsSELECT O.*FROM Orders O,
#PageIndex PageIndexWHERE O.OrderID = PageIndex.OrderID AND PageIndex.IndexID > @PageLowerBound AND PageIndex.IndexID < @PageUpperBoundORDER BY PageIndex.IndexID
END
------解决方案--------------------mark下