当前位置:编程学习 > C#/ASP.NET >>

存储过程里的output值为空

存储过程:

--获取在网站首页显示的特色商品
alter proc GetProductsOnCatalogPromotion
(
@pageIndex int,
@pageSize int,
@descriptionLength int,
@recordCount int output
)
as
select productId,productName,[description]=
case
when len([description])>@descriptionLength then substring([description],1,@descriptionLength)+'……'
else description
end
,price,image1FileName,image2FileName,author,publisherId,(select publisherName from Publisher where publisherId = p.publisherId) as publisherName
,publishDate,discount from(
select row_number() over(order by productid) as rownum,* from product where onCatalogPromotion = 1
)as p
where rownum between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize
select @recordCount = count(*) from product where onCatalogPromotion = 1
go

数据访问层代码

--获取在网站首页显示的特色商品
alter proc GetProductsOnCatalogPromotion
(
@pageIndex int,
@pageSize int,
@descriptionLength int,
@recordCount int output
)
as
select productId,productName,[description]=
case
when len([description])>@descriptionLength then substring([description],1,@descriptionLength)+'……'
else description
end
,price,image1FileName,image2FileName,author,publisherId,(select publisherName from Publisher where publisherId = p.publisherId) as publisherName
,publishDate,discount from(
select row_number() over(order by productid) as rownum,* from product where onCatalogPromotion = 1
)as p
where rownum between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize
select @recordCount = count(*) from product where onCatalogPromotion = 1
go

问:存储过程中的output值即par[3]怎么为null,代码哪里出问题了? --------------------编程问答-------------------- 额~~好像贴错了
数据访问层代码

//获取在网站首页显示的特色商品
        public List<ProductInfo> GetProductsOnCatalogPromotion(int pageIndex, out int recordCount)
        {
            List<ProductInfo> list = new List<ProductInfo>();
            ReaderConfig rc = new ReaderConfig();
            SqlParameter[] par = new SqlParameter[]
            {
                new SqlParameter(PRAM_PAGEINDEX,pageIndex),
                new SqlParameter(PRAM_PAGESIZE,rc.PageSize),
                new SqlParameter(PRAM_DESCRIPTIONLENGTH,rc.DescriptionLength),
                new SqlParameter(PRAM_RECORDCOUNT,SqlDbType.Int)
            };

            par[3].Direction = ParameterDirection.Output;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, PROC_GETPRODUCTSONCATALOGPROMOTION, par))
            {
                while (reader.Read())
                {
                    ProductInfo p = new ProductInfo();
                    p.productId = Convert.ToInt32(reader["productID"]);
                    p.productName = reader["productName"].ToString();
                    p.description = reader["description"].ToString();
                    p.price = Convert.ToDouble(reader["price"]);
                    p.image1FileName = reader["image1FileName"].ToString();
                    p.image2FileName = reader["image2FileName"].ToString();
                    p.author = reader["author"].ToString();
                    p.publisherId = Convert.ToInt32(reader["publisherId"]);
                    p.publisherName = reader["publisherName"].ToString();
                    p.publishDate = Convert.ToDateTime(reader["publishDate"].ToString());
                    p.discount = Convert.ToInt32(reader["discount"]);
                    list.Add(p);
                }
                int page = Convert.ToInt32(par[3].Value);
                recordCount = (int)Math.Ceiling(Convert.ToDouble(page) / 10);
            }
            return list;
        }
--------------------编程问答-------------------- comm.Parameters["@count"].Direction = ParameterDirection.Output;
@count int = 0 output 
exec sp_executesql @strSQL,N'@count int output',@count output
--------------------编程问答--------------------
引用 2 楼 wuyq11 的回复:
comm.Parameters["@count"].Direction = ParameterDirection.Output;
@count int = 0 output 
exec sp_executesql @strSQL,N'@count int output',@count output

什么意思…… --------------------编程问答-------------------- 学习了
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,