When executing a stored procedure through C#, the value stored in the table does not change.
But when the stored procedure is executed through SQL Server Management Studio, it is executed correctly.
This is my C# code:
DatabaseLibrary.ParametersClear();
DatabaseLibrary.command.Parameters.Add(new SqlParameter("@guid", SqlDbType.UniqueIdentifier)).Value = formGuid;
DatabaseLibrary.command.Parameters.Add(new SqlParameter("@val", SqlDbType.Float)).Value = (Sumsrc.Net * Convert.ToDouble(ParityTxt.Text));
DatabaseLibrary.command.Parameters.Add(new SqlParameter("@in", SqlDbType.Bit)).Value = input ? 1 : 0;
DatabaseLibrary.command.Parameters.Add(new SqlParameter("@operation", SqlDbType.Bit)).Value = 1;
DatabaseLibrary.ExecuteStoredProcedure(StoredProcedure.AccountUpdate);
Stored procedure code:
CREATE PROCEDURE [dbo].[AccountUpdate]
@guid uniqueidentifier,
@val float,
@in bit, -- 1 or 0
@operation bit -- 1 or 0
AS
BEGIN
DECLARE @oldVal float
IF (@in > 0)
BEGIN
IF (@operation > 0)
BEGIN
SET @oldVal = (SELECT ISNULL(Debit, 0) FROM ac00 WHERE GUID = @guid)
UPDATE ac00
SET [Debit] = (@oldVal + @val)
WHERE GUID = @guid
END
ELSE
BEGIN
SET @oldVal = (SELECT ISNULL(Debit, 0) FROM ac00 WHERE guid = @guid)
UPDATE ac00
SET [Debit] = (@oldVal - @val)
WHERE GUID = @guid
END
END
ELSE
BEGIN
IF (@operation > 0)
BEGIN
SET @oldVal = (SELECT ISNULL(Credit, 0) FROM ac00 WHERE GUID = @guid)
UPDATE ac00
SET [Credit] = (@oldVal + @val)
WHERE GUID = @guid
END
ELSE
BEGIN
SET @oldVal = (SELECT ISNULL(Credit, 0) FROM ac00 WHERE GUID = @guid)
UPDATE ac00
SET [Credit] = (@oldVal - @val)
WHERE GUID = @guid
END
END
END