I have to create a banking app for my class using c#. My problem is that when I try to subtract an amount of money in one account, let's say 10$ in one account, the value in my table goes up by like 1000$ instead of going down of 10$.
first of all i have a stored procedure name 'retrait' that goes like that
CREATE PROCEDURE retrait
@montantRetrait money,
@numCompte int
AS
BEGIN
UPDATE tblCompte
SET solde = (SELECT SUM(solde) FROM tblCompte) - (SELECT SUM(@montantRetrait))
WHERE numeroCompte = @numCompte
END
Mnd my C# code is like this:
private void btnConfirmer_Click(object sender, RoutedEventArgs e)
{
int typeTransaction = cmbTransaction.SelectedIndex;
if(verifierSaaisie())
{
switch (typeTransaction)
{
case 0:
// Creation de la commande avec procedure stocker
commande = new SqlCommand("retrait", connexion);
commande.CommandType = CommandType.StoredProcedure;
// Ajout de valeur a nos parametre
commande.Parameters.Add("@montantRetrait", SqlDbType.Int).Value = textMontant.Text;
commande.Parameters.Add("@numCompte", SqlDbType.Int).Value = cmbProvenance.Text;
try
{
// ouverture de la connexion
connexion.Open();
// Execution de la commande
int ligne = commande.ExecuteNonQuery();
if (ligne != 0)
{
if (MessageBox.Show("Transaction effectuer avec succes. Voulez vous effectuer une autre transaction ?", "Message", MessageBoxButton.YesNo, MessageBoxImage.Question)== MessageBoxResult.No)
{
this.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connexion.Close();
cmbTransaction.SelectedIndex = -1;
cmbProvenance.SelectedIndex = -1;
cmbDestination.IsEnabled = true;
textMontant.Text = string.Empty;
}
break;
}
}
}
}
Any advice would be great.