I'm new at SQL Server. I'm currently working on simple ATM simulation program just for practice, and I want to check whether the transfer is success or not (and by the way, I'm using Dapper ORM).
The code will be executed when I click the transfer button, here's some piece of the code:
try
{
var balance = sqlcon.ExecuteScalar<float>("GetClientBalance", pinParam, commandType: CommandType.StoredProcedure);
if (balance < transferAmount)
{
MessageBox.Show("Error: Your balance is not enough to transfer", "Transfer Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
var success = sqlcon.ExecuteScalar<bool>("TransferMoney", transferParam, commandType: CommandType.StoredProcedure);
if (success)
{
MessageBox.Show("Transfer Success! You just transfer to " + lblDesName.Text + " for " + lblAmount.Text, "Transfer Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(success.ToString());
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
The success
variable is always false
even though the stored procedure (TransferMoney
) runs successfully. I'm afraid I just made a silly mistake here.
Edit: This is the query of TransferMoney
stored procedure:
USE [Stellar]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[TransferMoney]
@PIN varchar(6),
@DestinationNumber varchar(20),
@Amount float
AS
BEGIN
UPDATE Client.Cards
SET Balance -= (@Amount + 0.5)
WHERE PIN = @PIN
UPDATE Client.Cards
SET Balance += @Amount
WHERE Client.Cards.CardNumber = @DestinationNumber
UPDATE Client.Cards
SET LastTransaction = CAST(GETDATE() AS DATE)
WHERE PIN = @PIN
END
Thanks!
TransferMoney
? – John Woo Mar 2 '18 at 7:42success
depends upon output of your store procedure. – rahulaga_dev Mar 2 '18 at 7:46success
returnsfalse
– Alfonso Mar 2 '18 at 7:55