mardi 21 avril 2015

Error while retrieving data from OleDb database

I am working on Bank project for which I have written this code for Deposit/Withdrawal Transaction however, I am getting errors as

Error 1 'string' does not contain a definition for 'getDouble' and no extension method 'getDouble' accepting a first argument of type 'string' could be found

Error 2 The name 'result' does not exist in the current context


The Form: http://ift.tt/1GeSJ6O
The Database: http://ift.tt/1IrwCY7

Here is the form code

public partial class DepWithDraw : Form
    {
        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";

        }

        private void DepText_Click(object sender, EventArgs e)
        {
            dc.Open();
            OleDbCommand df = new OleDbCommand("Select balance From Accounts Where [acctNO] = ?", dc);
            int updateSet = 0;
            double balance = 0.00;
            double newBalance;
            double depAmount;
            String result;
            newBalance = balance + depAmount;
            string update = "Update Accounts Set Balance = '" + BalDepText.Text + "' Where acctNO = '" + AcctDep.Text + "';";
             balance = result.getDouble("Balance");
            balance = newBalance;
            df.Parameters.AddWithValue("@AcctNo", AcctDep.Text);
            df.Parameters.AddWithValue("@Balance", BalDepText.Text);
            df.ExecuteNonQuery();
            dc.Close();
        }

        private void WithText_Click(object sender, EventArgs e)
        {
            dc.Open();
            OleDbCommand df = new OleDbCommand("Select balance From Accounts Where [acctNO] = ?", dc);
            String update = null;
            int updateSet = 0;
            double balance = 0.00;
            double newBalance;
            double withdrawal;
            balance = result.getDouble("Balance");
            if (balance < withdrawal)
            {
                MessageBox.Show( "Insufficcient Funds");
                throw new Exception();
            }
            else
            {

                /* sets new balance and updates the current database account balance */
                newBalance = balance - withdrawal;
                update = "Update Accounts Set Balance = '" + balWithbtn.Text + "' Where acctNo = '" + AcctWithText.Text + "';";
                df.ExecuteNonQuery();
                this.balance = newBalance;

            }

            df.Parameters.AddWithValue("@AcctNo", AcctWithText.Text);
            df.Parameters.AddWithValue("@Balance", balWithbtn.Text);
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire