SQL Server分页模板
Posted 轴轴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server分页模板相关的知识,希望对你有一定的参考价值。
SQL Server分页模板
WITH T AS
(
SELECT ROW_NUMBER() OVER(ORDER BY AlbumId ) AS row_number, *
FROM (SELECT AlbumId,Title,GenreId,ArtistId,Price,AlbumArtUrl FROM albums WHERE 1=1 and GenreId = @GenreId) as A
)
SELECT * FROM T WHERE row_number > @StartRowNum AND row_number <= @EndRowNum
SELECT COUNT(1) FROM (SELECT AlbumId,Title,GenreId,ArtistId,Price,AlbumArtUrl FROM albums WHERE 1=1 and GenreId = @GenreId) AS B
这里涉及到多查询结果集的编程处理
IDataReader reader = null;
reader = CurrentDatabase.ExecuteReader(dbCommand);
using (reader)
{
objList = GetListFromReader<T>(reader);
if (reader.NextResult() && reader.Read())
RecordCount = reader.GetInt32(0);
else
RecordCount = 0;
}
return objList;
其中IDataReder这里是Microsoft.Practices.EnterpriseLibrary.Data实现
以上是关于SQL Server分页模板的主要内容,如果未能解决你的问题,请参考以下文章
使用实体框架迁移时 SQL Server 连接抛出异常 - 添加代码片段