我正在運行帶硬編碼值的存儲過程。該命令成功執行,沒有任何錯誤。但是數據並沒有在數據庫中更新。如果我用SQL Server運行該存儲過程,數據正在更新。我的錯誤是什麼?這個存儲過程爲什麼不更新數據庫中的數據?
C#代碼
using (SqlTransaction sqlTrans = con.BeginTransaction())
{
using (SqlCommand AdjustTax = new SqlCommand("GP_SOP_AdjustTax", con, sqlTrans))
{
try
{
AdjustTax.CommandType = CommandType.StoredProcedure;
AdjustTax.Parameters.Add("@IN_SOPType", SqlDbType.Int).Value = 3;
AdjustTax.Parameters.Add("@IN_SOPNo", SqlDbType.VarChar).Value = "stdinv2278";
AdjustTax.Parameters.Add("@IN_AdjustAmount", SqlDbType.Int).Value = 0.04;
AdjustTax.Parameters.Add("@O_iError", SqlDbType.Int, 250);
AdjustTax.Parameters["@O_iError"].Direction = ParameterDirection.Output;
if (con == null || con.State == ConnectionState.Closed)
{
con.Open();
}
AdjustTax.ExecuteNonQuery();
int Error = (int)AdjustTax.Parameters["@O_iError"].Value;
if (Error == 0)
{
MessageBox.Show("Tax is Adjusted");
}
if (Error != 0)
{
MessageBox.Show("Error No:" + Error1);
}
sqlTrans.Commit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
sqlTrans.Rollback();
}
finally
{
con.Close();
}
}
}
SQL Server代碼
DECLARE @return_value int,
@O_iError int
EXEC @return_value = [dbo].[GP_SOP_AdjustTax]
@IN_SOPType = 3,
@IN_SOPNo = 'stdinv2278',
@IN_AdjustAmount = 0.04,
@O_iError = @O_iError OUTPUT
SELECT @O_iError as N'@O_iError'
SELECT 'Return Value' = @return_value
GO
請證實有關即@IN_AdjustAmount – TechDo
感謝答覆第三個輸入參數的DB int類型。類型是numaric – Kavitha
如果類型是numaric ..那麼哪種類型有我設置在C#代碼。 – Kavitha