假设有存储过程如下:
CREATE PRoc sp_uptmp @tmpName varchar()@srcPos varchar()
as
Begin TRAN
insert into t_template values(@tmpName@srcPos)
COMMIT
return isnull(@@identity)
GO
在 里面获取返回值的方法为(c#):
SqlConnection dbconn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(sp_uptmpdbconn);
cmdCommandType = CommandTypeStoredProcedure;
SqlParameter tmpName = cmdParametersAdd(@tmpNameSqlDbTypeVarChar);
SqlParameter srcPos = _cmdParametersAdd(@srcPosSqlDbTypeVarChar);
SqlParameter rtnval = cmdParametersAdd(rvalSqlDbTypeInt);
tmpNameDirection = ParameterDirectionInput;
srcPosDirection = ParameterDirectionInput;
rtnvalDirection = ParameterDirectionReturnValue;
tmpNameValue = ;
srcPosValue = ;
dbconnOpen();
cmdExecuteNonQuery();
dbconnClose();
tmpid = (int)rtnvalValue; //此处即为返回值