当前位置: 代码迷 >> Sql Server >> 怎么在C#中获取存储过程的参数
  详细解决方案

怎么在C#中获取存储过程的参数

热度:15   发布时间:2016-04-27 20:12:38.0
如何在C#中获取存储过程的参数
现有存储过程:
create   procedure   ggg
@aa   float=10.0,
@bb   int=0   output,
@cc   float=1.0   output
as
declare   @sql   nvarchar(4000)
set   @sql= 'select   @cc=count(*)   from   Pub_Dic_CorpType '
exec   sp_executesql   @sql,N '@cc   float   output ',   @cc   output
select   @cc
set   @bb=ceiling(@[email protected])

[email protected]   和   @cc获取到C#的变量中,然后在页面输出

------解决方案--------------------
SqlCommand cmd = new SqlCommand( "ggg ", myConn);
cmd.CommandType = CommandType.StoredProcedure;

//输入值aa
SqlParameter a1 = new SqlParameter( "@aa ", SqlDbType.Float);
a1.Value=11;
cmd.Parameters.Add(a1);

//返回值 bb
SqlParameter bb = new SqlParameter( "@bb ", SqlDbType.Int,4);
bb.Direction = ParameterDirection.Output;
cmd.Parameters.Add(i);

cmd.ExecuteNonQuery();

string strReturn = bb.Value.ToString();
  相关解决方案