Click here to Skip to main content

Member 9417196 asked:

Open original thread
I'm not sure why my variables pin, firstName, and balance aren't giving correct values. When I run the app and pick an account number, I am able to enter a pin, and the messageBox displays welcome, but not the member's name. Then, when I hit the balance button, it prints 0 everytime. Im not sure why this is happening.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SQLDll;
 
namespace WindowsFormsApplication14
{
 
    public partial class Form1 : Form
    {
        private Connection myConnection;
        private Statement myStatement;
        private ResultSet myResultSet;
        String databaseURL = "http://www.boehnecamp.com/phpMyAdmin/razorsql_mysql_bridge.php";
        private string pin ,firstName, userAccountNumber;
        private double balance;
        private double withdraw = 0;
        private double deposit = 0;
        bool buttonClicked, buttonClicked2;
 
        public Form1()
        {
            InitializeComponent();
            
            try
            {
                //connect to database
                SQL sql = new SQL();
                myConnection = sql.getConnection(databaseURL);
                //create Statement for executing SQL
                myStatement = myConnection.createStatement(databaseURL);
                loadAccountNumbers();
                updateBalance();
            }
            catch (Exception)
            {
                Console.WriteLine("Cannot connect to database server");
            }
            //close statement and database connection 
           myStatement.close();
           myConnection.close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {   
        }
 
        
        private void retrieveAccountInformation()
        {
            //get account info
            try
            {
                myResultSet = myStatement.executeQuery("SELECT pin, " +
               "firstName, balanceAmount FROM accountInformation " +
               "WHERE accountNumber = '" + userAccountNumber + "'");
 
                //get next result
                if (myResultSet.next())
                {
                    pin = myResultSet.getString("pin");
                    firstName = myResultSet.getString("firstName");
                    balance = myResultSet.getDouble("balanceAmount");
                }
                myResultSet.close(); //close myResultSet
            }//end try
            catch (Exception)
            {
                Console.WriteLine("Error in retrieveAccountInformation");
            }
        }// end method retrieveAccountInformation

        //update database after withdrawing
        private void updateBalance()
        {
            //update balance in database
            try
            {
                myStatement.executeUpdate("UPDATE accountInformation" +
                               " SET balanceAmount = " + balance + " WHERE " +
                               "accountNumber = '" + userAccountNumber + "'");
 
            }
            catch (Exception)
            {
                Console.WriteLine("Error in updateBalace");
            }
        }//end method updateBalance

        private void accountNumberComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            accountNumberComboBox.Enabled = false;
            numberTextField.Text = " ";
            messageTextArea.Text = "Enter your PIN #.";
            buttonDone.Enabled = true;
 
        }
        private void buttonEnter_Click(object sender, EventArgs e)
        {
            retrieveAccountInformation();
                numberTextField.Text = " ";
                buttonEnter.Enabled = false;
                buttonBalance.Enabled = true;
                buttonWithdraw.Enabled = true;
                buttonDeposit.Enabled = true;
                messageTextArea.Text = "Welcome" + firstName;
                updateBalance();
 
            
        }
 
        private void buttonBalance_Click(object sender, EventArgs e)
        {
            retrieveAccountInformation();
            updateBalance();
            messageTextArea.Text=(balance.ToString());
            //display balance to messageTextArea
        }
 

   
    }
}
 
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid