当前位置: 代码迷 >> ASP.NET >> 50分求存储过程返回值解决方法
  详细解决方案

50分求存储过程返回值解决方法

热度:8549   发布时间:2013-02-26 00:00:00.0
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
  相关解决方案