日期:2014-05-19  浏览次数:20454 次

50分求存储过程返回值
存储过程如下:
CREATE   PROCEDURE   pmc_count(@comtype   varchar(50))
as
declare   @comcount   int
set   @comcount=(select   count(*)   from   pmc   where   comtype=@comtype
GO
------------------
我要用count.text得到@comcount的值,怎么做??

------解决方案--------------------
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype
..
select @comcount '输出
GO
然后执行存储过程,输出到结果集

------解决方案--------------------
存储过程没写对
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype)
return @comcount
GO

SqlConnection con=new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd=new SqlCommand(con);
cmd.CommandText= "pmc_count ";
cmd.CommandType=System.Data.CommandType.StoredProcedure;
SqlParameter pa=new SqlParameter( "@comtype ",System.Data.SqlDbType.VarChar,50);
pa.Value = "testvalue ";
cmd.Parameters.Add(pa);

int returnValue = (int)cmd.ExecuteScalar();
count.Text = returnValue.ToString();

------解决方案--------------------
把@comcount 定义成output类型的参数,由存储过程返回这个值:

CREATE PROCEDURE pmc_count
(
@comtype varchar(50),
@comcount int output
)
as
set @comcount=(select count(*) from pmc where comtype=@comtype
GO