ASP.NET中怎么接受储存过程的返回值?
存储过程如下:
CREATE PROCEDURE UP_jj_zjtzsq_InsRec
@zjtzsqd varchar(20) OUTPUT,
@dwbh varchar(20)
AS
@zjtzsqd = "1 "; //这里是自动增长值,我先这样写了
INSERT INTO jj_zjtzsq([zjtzsqd],[dwbh])VALUES(@zjtzsqd,@dwbh)
ASP.NET中的代码如下:
private SqlParameter GetSqlParameter(string name, ParameterDirection direction, object value)
{
SqlParameter p = new SqlParameter(name, value);
p.Direction = direction;
return p;
}
private SqlParameter[] GetInsertParameterValues()
{
SqlParameter[] prams = new SqlParameter[2];
prams[0] = GetSqlParameter( "@zjtzsqd ", ParameterDirection.Output, this.zjtzsqd);
prams[1] = GetSqlParameter( "@dwbh ", ParameterDirection.Input, this.dwbh);
}
private void Insert()
{
SqlParameter[] parameterValues = GetInsertParameterValues();
SqlHelper.ExecuteNonQuery(Common.Config.ConnectionString, CommandType.StoredProcedure, "UP_jj_zjtzsq_InsRec ", parameterValues);
key = parameterValues[0].Value.ToString();
_zjtzsqd = parameterValues[0].Value.ToString();
}
我这样做没办法得到存储过程的返回值?
请各位高手指点一下
------解决方案--------------------
public void ggins(out int id,int week,string gg,string specup)
{
SqlConnection cntable= new SqlConnection(ConfigurationSettings.AppSettings[ "cndatabase "].Trim());
cntable.Open();
SqlParameter[] parameters={
new SqlParameter( "@id ",SqlDbType.Int),
new SqlParameter( "@week ",SqlDbType.Int),
new SqlParameter( "@ggtop ",SqlDbType.VarChar,8000),
new SqlParameter( "@specup ",SqlDbType.VarChar,8000)
};
parameters[0].Direction=ParameterDirection.Output;
parameters[1].Value=week;
parameters[2].Value=ggtop;
parameters[3].Value=specup;
dbmos.ExecuteNonQuery( "proc_ggtopins " ,parameters,cnmusic,out id);
cntable.Close ();
}
//对应的存储过程
create procedure [dbo].[proc_ggtopins]
--用于插入新的手写链接,插入成功,返回最后插入的id ,不成功则放回-2
(
@id int=1 output
,@week int =0
,@ggtop varchar(8000)
,@specup varchar(8000)
)
as
if exists (select id from tb_ggtop where week=@week)
set @id=-2
else
begin
insert into tb_ggtop (week,ggtop,specup) values (@week,@ggtop,@specup)