Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Withdraw and Deposit Access Database

$
0
0
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);
            }
        }
    }

Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>