存储过程输出参数的调用(简单例子)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
存储过程输出参数的调⽤(简单例⼦)
如:存储过程如下:
create PROC [dbo].[exchange_UserFinance]
@uId int,
@uType int,
@uAmount decimal(9,2),
@uAfterRemainAmount decimal(9,2),
@uOPid int,
@uText varchar(200),
@uNote1 varchar(200),
@uNote2 varchar(200),
@uNote3 varchar(200),
@uRemainAmount decimal(9,2) output
AS
DECLARE @uTime datetime
SET @uTime=getdate()
SET @uRemainAmount=0.00
BEGIN
BEGIN TRAN
INSERT INTO [IP_UserFinance](
[uId],[uTime],[uType],[uAmount],[uAfterRemainAmount],[uOPid],[uText],[uNote1],[uNote2],[uNote3]
)VALUES(@uId,@uTime,@uType,@uAmount,@uAfterRemainAmount,@uOPid,@uText,@uNote1,@uNote2,@uNote3) IF @@RowCount<>1
BEGIN
ROLLBACK TRAN
SET @uRemainAmount=0
RETURN
END
UPDATE [IP_UserRemainAmount] SET [uRemainAmount] = @uAfterRemainAmount,[uTime] = @uTime WHERE
IF @@RowCount<>1
BEGIN
ROLLBACK TRAN
SET @uRemainAmount=0
RETURN
END
COMMIT TRAN
SET @uRemainAmount=(SELECT uRemainAmount FROM IP_UserRemainAmount WHERE )
END
.net调⽤
public static decimal modifyOfficeOrAgentFinance(IP_UserFinance agentmodel)
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter ("@uId",SqlDbType.Int ,4),
};
parms[0].Value = agentmodel.uId;
object remainagent = null;
try
{
remainagent = SqlHelper.ExecuteScalar(SqlHelper.connectionString, CommandType.StoredProcedure, "WSSelectIP_UserInFoFinanceOne", parms);
if (remainagent == null)
{
return -1;
}
}catch(Exception)
{
return 0;
}
SqlParameter[] parameters = {
new SqlParameter("@uId", SqlDbType.Int,4),
new SqlParameter("@uType", SqlDbType.Int),
new SqlParameter("@uAmount", SqlDbType.Decimal,9),
new SqlParameter("@uAfterRemainAmount", SqlDbType.Decimal,9),
new SqlParameter("@uOPid", SqlDbType.Int,4),
new SqlParameter("@uText", SqlDbType.VarChar,200),
new SqlParameter("@uNote1", SqlDbType.VarChar,200),
new SqlParameter("@uNote2", SqlDbType.VarChar,200),
new SqlParameter("@uNote3", SqlDbType.VarChar,200),
new SqlParameter("@uRemainAmount", SqlDbType.Decimal)};
if (Convert.ToDecimal(remainagent) < agentmodel.uAmount)
{
return -2;
}
parameters[0].Value = agentmodel.uId;
parameters[1].Value = agentmodel.uType;
parameters[2].Value = agentmodel.uAmount;
parameters[3].Value = Decimal.Add(Convert.ToDecimal(remainagent), agentmodel.uAmount);
parameters[4].Value = agentmodel.uOPid;
parameters[5].Value = agentmodel.uText;
parameters[6].Value = agentmodel.uNote1;
parameters[7].Value = agentmodel.uNote2;
parameters[8].Value = agentmodel.uNote3;
parameters[9].Direction = ParameterDirection.Output;
try
{
Convert.ToDecimal(SqlHelper.ExecuteScalar(SqlHelper.connectionString, CommandType.StoredProcedure, "exchange_UserFinance", parameters));
return Convert.ToDecimal(parameters[9].Value);
}
catch
{
return 0.00m;
}
}。