这个问题在前面已经讨论过了,但这并不能帮助我解决问题。
这是我的以下存储过程,可避免进行投资。
ALTER procedure [dbo].[mark_inactive]
@order_id int,
@intResult int output
as
BEGIN transaction
Declare @Error as int
update investment_orders set investment_active = 0 where order_id = @order_id
-- if error in saving details
Select @Error = @@error
if(@Error<>0)
Begin
Set @intResult = 0
rollback transaction
return
End
commit transaction
return @intResult
和代码隐藏函数来调用过程
public int ExecuteSqlSP(SqlParameter[] arrParam, string strSPName)
{
OpenConnection();
_mDataCom.CommandType = CommandType.StoredProcedure;
_mDataCom.CommandText = strSPName;
_mDataCom.CommandTimeout = 30;
for (int i = 0; i < arrParam.Length; i++)
{
_mDataCom.Parameters.Add(arrParam[i]);
}
_mDataCom.ExecuteNonQuery();
int intResult = Int32.Parse(_mDataCom.Parameters["@intResult"].Value.ToString());
CloseConnection();
DisposeConnection();
return intResult;
}
虽然更新了一行,但以下错误显示
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
对不起,如果有任何错误。请帮助我解决问题。
谢谢
答案 0 :(得分:1)
成功更新后,您不会从编写的存储过程中返回任何值。
您的程序应类似于
ALTER procedure [dbo].[mark_inactive]
@order_id int,
@intResult int output
as
BEGIN transaction
Declare @Error as int
update investment_orders set investment_active = 0 where order_id = @order_id;
SET @intResult = 1; // 1 OR whatever desired value you wanna return
-- if error in saving details
Select @Error = @@error
if(@Error<>0)
Begin
Set @intResult = 0
rollback transaction
return
End
commit transaction
return @intResult