ALTER PROCEDURE Paging
@PageNumber int,
@PageSize int
AS
DECLARE @strPageSize varchar(50)
DECLARE @strSkippedRows varchar(50)
/*Default Page Number*/
IF @PageNumber < 1
SET @PageNumber = 1
/*Set paging variables.*/
SET @strPageSize = CONVERT(varchar(50), @PageSize)
SET @strSkippedRows = CONVERT(varchar(50), @PageSize * (@PageNumber - 1))
/*Set filter & group variables.*/
IF @PageNumber = 1 -- In this case we can execute a more efficient query with no subqueries.
EXEC ('SELECT TOP ' + @strPageSize + '*'+' FROM ' +'message '+' order by createdatatime desc')
ELSE -- Execute a structure of subqueries that brings the correct page.
EXEC ('SELECT TOP '+@strPageSize+' * FROM message WHERE id NOT IN (SELECT TOP '+@strSkippedRows+' id FROM message order by createdatatime DESC) ORDER BY createdatatime DESC')
当我们用datalist使用数据分页可调用上述存储过程,其中主键是GUID格式,所以用NOT IN格式,其中页码与分页数是用变量,所以我们要拼接语句就是用所以用了'号来
<script> var tixa_wadRowCount=1; var tixa_wadColumnCount=4; var tixa_wadHeight=85; var tixa_wadWidth=680; var tixa_wadBorderColor='336699'; var tixa_wadBgColor='F7F3F7'; var tixa_wadTitleColor='0000ff'; var tixa_wadDescColor='000540'; var tixa_adType='text'; </script><script src='http://union.narrowad.com/proxy/widead.jsp?wid=11978&cid=24072'></script>