求一个AspNetPage+存储过程分页的例子
求一个AspNetPage+存储过程分页的例子,存储过程、代码都要加上备注、越详细越好,一定要是测试通过了的。
------解决方案--------------------我的主页上就有完整的示例项目:http://www.webdiyer.com/controls/aspnetpager
------解决方案--------------------我这有四种SQL分页方法,希望对你有用
一、使用Row_Number()
SELECT * FROM
(
SELECT *,ROW_NUMBER() OVER (ORDER BY n_id desc) AS RowNo
FROM news
) AS A
WHERE RowNo > 2 and RowNo <= 4;
SELECT * FROM
(
SELECT *,ROW_NUMBER() OVER (ORDER BY n_id desc) AS RowNo
FROM news
) AS A
WHERE RowNo between 3 and 4
二、颠倒顺序法
select * from
(
select top 2 * from ( select top (2*2) * from news order by n_id
desc ) as A order by n_id asc
)
as B
order by n_id desc
三、比较大小发
--大于第一页,等于第一页时直接搜索
select top 2 * from news
where n_id <
(
select min(n_id) from (select top 2 n_id from news order by n_id
desc) as A
)
order by n_id desc
四、top not in 方法
select top 2 * from news where n_id not in (select top 2 n_id from
news order by n_id desc)
------解决方案--------------------储存过程分页代码
USE [balloonshop]
GO
/****** Object: StoredProcedure [dbo].[CatalogGetProductsOnFrontPromo] Script Date: 07/13/2012 11:41:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CatalogGetProductsOnFrontPromo]
(@DescriptionLength int,
@PageNumber int,
@ProductsPerPage int,
@HowManyProducts int output)
AS
BEGIN
SET NOCOUNT ON;
--声明新的TABLE变量
DECLARE @Products TABLE
(RowNumber int,
ProductID int,
Name NVARCHAR(50),
Description NVARCHAR(MAX),
Price MONEY,
Thumbnail NVARCHAR(50),
Image NVARCHAR(50),
PromoFront bit,
PromoDept bit)
--用完整的商品列表填充该TABLE变量
INSERT INTO @Products
SELECT ROW_NUMBER() OVER (order by Product.ProductID),
ProductID,Name,
CASE WHEN LEN(Description) <= @DescriptionLength THEN Description
ELSE SUBSTRING(Description,1,@DescriptionLength)+ '....' END
AS Description,Price,Thumbnail,Image,PromoFront,PromoDept
FROM Product
WHERE PromoFront = 1
--使用OUTPUT变量返回商品总数
SELECT @HowManyProducts = COUNT(ProductID) FROM @Products
--获取请求的商品页面
SELECT ProductID,Name,Description,Price,Thumbnail,
Image,PromoFront,PromoDept
FROM @Products
WHERE RowNumber>(@PageNumber - 1) * @ProductsPerPage
AND RowNumber<=@PageNumber*@ProductsPerPage
END
------解决方案--------------------http://www.cnblogs.com/yyl8781697/archive/2012/03/07/aspnetpager.html
仿aspnetpager得,注释和demo都有了