首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-01-08 
50分求存储过程返回值存储过程如下:CREATEPROCEDUREpmc_count(@comtypevarchar(50))asdeclare@comcountint

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

热点排行