你用的什么數(shù)據(jù)庫? 分頁存儲過程怎么寫的?
10000 條數(shù)據(jù)是很小的數(shù)據(jù)量,應(yīng)該是你的分頁存儲過程有問題。
使用的是sql server2005,存儲過程如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AAAACommon_Page2005]
@TableName varchar(500), --表名
@Fields varchar(5000) = '*', --字段名(全部字段為*)
@OrderField varchar(5000), --排序字段(必須!支持多字段)
@sqlWhere varchar(5000) = Null,--條件語句(不用加where)
@pageSize int, --每頁多少條記錄
@pageIndex int = 1 --指定當前為第幾頁
AS
BEGIN
Declare @sql nvarchar(4000),@totalRecord as int,@TotalPage as int --返回總頁數(shù)
--SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
if (@SqlWhere='' or @sqlWhere=NULL)
set @sql = 'select @totalRecord = count(*) from ' + @TableName
else
set @sql = 'select @totalRecord = count(*) from ' + @TableName + ' where ' + @sqlWhere
EXEC sp_executesql @sql,N'@totalRecord int OUTPUT',@totalRecord OUTPUT--計算總記錄數(shù)
--計算總頁數(shù)
select @TotalPage=CEILING((@totalRecord+0.0)/@PageSize)
if (@SqlWhere='' or @sqlWhere=NULL)
set @sql = 'Select * FROM (select ROW_NUMBER() Over(order by ' + @OrderField + ') as rowId,' + @Fields + ' from ' + @TableName
else
set @sql = 'Select * FROM (select ROW_NUMBER() Over(order by ' + @OrderField + ') as rowId,' + @Fields + ' from ' + @TableName + ' where ' + @SqlWhere
--處理頁數(shù)超出范圍情況
if @PageIndex<=0
Set @pageIndex = 1
if @pageIndex>@TotalPage
Set @pageIndex = @TotalPage
--處理開始點和結(jié)束點
Declare @StartRecord int
Declare @EndRecord int
set @StartRecord = (@pageIndex-1)*@PageSize + 1
set @EndRecord = @StartRecord + @pageSize - 1
--繼續(xù)合成sql語句
set @Sql = @Sql + ') as t where rowId between ' + Convert(varchar(50),@StartRecord) + ' and ' + Convert(varchar(50),@EndRecord)
--print @Sql
Exec(@Sql)
---------------------------------------------------
If @@Error <> 0
Begin
select -1
End
Else
Begin
select @totalRecord ---返回記錄總數(shù)
End
END