none
Withdraw and Deposit Access Database RRS feed

  • Question

  • I am working on the bank project. I am able to 
    1.) Login

    3.) Create a new Account

    5.) Login as Admin(id=”admin”, pw=”123”) and Create/Delete Customers
    What I am unable to do is <br>4.) Deposit to or Withdraw from any Account
    Things to keep in mind with my bank project:
    1. It is an Access Database
    2.It is a beginning program for beginners


    I attempting to:
    1. Get the program to deposit entering the AcctNo and the Balance
    2. Get the program to Withdraw entering the AcctNo and the Balance.


    The Program runs, but once I click towards this form, the deposit and withdrawal does not actually function nor passes information through the form.

    THE DATABASE: http://puu.sh/hiYKZ/01e0da1578.png

          public partial class DepWithDraw : Form
            {
                //opening connection
                OleDbConnection dc = new OleDbConnection();
                OleDbDataAdapter da = new OleDbDataAdapter();
                DataTable dt = new DataTable();
                public DepWithDraw()
                {
                    InitializeComponent();
                    dc.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ChattBankMDB.mdb";
        
                }
                //Depositing Button code
                private void DepText_Click(object sender, EventArgs e)
                {
                    //Opening Connection for Deposit
                    dc.Open();
                    OleDbCommand df = new OleDbCommand("Select balance From Accounts Where [acctNO] = ?", dc);
                    int updateSet = 0;
                    double balance = 0.00;
                    double newBalance;
                    double depAmount= 0;
                    string result = null;
                    newBalance = balance + depAmount;
                    string update = "Update Accounts Set Balance = '" + BalDepText.Text + "' Where acctNO = '" + AcctDep.Text + "';";
                     //balance = result.getDouble("Balance");
                    balance = newBalance;
                    //Textbox Parameters
                    df.Parameters.AddWithValue("@AcctNo", AcctDep.Text);
                    df.Parameters.AddWithValue("@Balance", BalDepText.Text);
        
                    //Executing code
                    df.ExecuteNonQuery();
                    //Closing Connection
                    dc.Close();
                }
                //Withdrawing Button Code
                private void WithText_Click(object sender, EventArgs e)
                {
                    //Opening connection for withdraw
                    dc.Open();
                    OleDbCommand df = new OleDbCommand("Select balance From Accounts Where [acctNO] = ?", dc);
                   
                    int updateSet = 0;
                    double balance = 0;
                    double newBalance;
                    double withdrawal=0;
                    balance = Convert.ToInt32(df.ExecuteScalar());
                    OleDbDataReader dr = df.ExecuteReader();
                    while (dr.Read())
                    {
                        double val = dr.GetDouble(0);//ordinal of column
                    }
                    if (balance < withdrawal)
                    {
                        MessageBox.Show( "Insufficcient Funds");
                        throw new Exception();
                    }
                    else
                    {
        
                        /* sets new balance and updates the current database account balance */
                        newBalance = balance - withdrawal;
                       String  update = "Update Accounts Set Balance = ? Where acctNO = ?";
                        df.ExecuteNonQuery();
                       balance = newBalance;
        
                    }
        
                    df.Parameters.AddWithValue("@AcctNo", AcctWithText.Text);
                    df.Parameters.AddWithValue("@Balance", balWithbtn.Text);
                }
            }
        }
    Wednesday, April 22, 2015 5:46 AM

All replies

  • Hi Felicity012910,

    About the withdraw and deposit logic you should think of by yourself. Thanks.

    Likewise here is a sample about how to create dataTable

    ID     user        date             deposit         withdraw     
    1       A        2014-01-21           100              0
    2       A        2014-01-21             0             30
    3       A        2014-01-21           300              0
    4       A        2014-01-23             0             20
    5       B        2014-01-23            20              0

    For more detailed information, please refer to http://www.codeproject.com/Questions/756093/efficient-way-for-sql-query-to-calculate-balance

    You'll get more inspirations.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    • Edited by Kristin Xie Thursday, April 30, 2015 3:36 AM
    Thursday, April 23, 2015 2:39 AM