Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7668579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:23:57+00:00 2026-05-31T15:23:57+00:00

try { sqlCommandWithdraw.Connection.Open(); sqlCommandWithdraw.Parameters[@cardNumber].Value = Class1.cardNumber; readdata = sqlCommandWithdraw.ExecuteReader(); while (readdata.Read()) { balanceDB =

  • 0
try
{
    sqlCommandWithdraw.Connection.Open();
    sqlCommandWithdraw.Parameters["@cardNumber"].Value = Class1.cardNumber;
    readdata = sqlCommandWithdraw.ExecuteReader();

    while (readdata.Read())
    {
        balanceDB = decimal.Parse(readdata["balance"].ToString());
    }

    decimal withdrawAmm = Convert.ToDecimal(textWithdraw.Text);
    balanceDB = balanceDB - withdrawAmm;
    sqlCommandWithdraw.Connection.Close();

    sqlCommandUpdate.Connection.Open();
    sqlCommandUpdate.Parameters["@cardNumber"].Value = Class1.cardNumber;
    sqlCommandUpdate.Parameters["@balanceDB"].Value = Class1.cardNumber;
    readdata = sqlCommandUpdate.ExecuteReader();
    MessageBox.Show(balanceDB +" Successfully Withdrawn");
}

I’m working on code for an ATM machine I’m a bit stuff on the withdraw it looks fine but doesn’t seem to change the balance to reflect the withdrawals in the database

My commands go like this (update)

update dbo.Accounts
set balance = @balanceDB
from dbo.ATMCards 
INNER JOIN dbo.Accounts ON dbo.ATMCards.accountID = dbo.Accounts.accountID
where (dbo.ATMCards.cardNumber = @cardNumber)

and this is my command to select the data

select dbo.Accounts.balance
from dbo.ATMCards 
INNER JOIN dbo.Accounts ON dbo.ATMCards.accountID = dbo.Accounts.accountID
where (dbo.ATMCards.cardNumber = @cardNumber)

Seems to run just fine added the message box to check it thanks for any help appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:23:58+00:00Added an answer on May 31, 2026 at 3:23 pm

    You are passing the credit card number to the parameter @balanceDB – this is the first mistake. Second, you do not use ExecuteReader to perform updates – use ExecuteNonQuery instead.

    EDIT
    I’ll do some clean-ups for you:

    try
    {
        try
        {
            sqlCommandWithdraw.Connection.Open();
            sqlCommandWithdraw.Parameters["@cardNumber"].Value = Class1.cardNumber;
    
            // Make sure to dispose of the reader, which also closes the reader, which
            // is important, because you can't perform any other selects on a connection
            // with an open reader!
            using (SqlDataReader reader = sqlCommandWithdraw.ExecuteReader())
            {
                // You will only get one line - also, your code also only evaluates
                // one result, so we can do the following:
                if (reader.Read())
                {
                    balanceDB = decimal.Parse(readdata["balance"].ToString());
                }
            }
        }
        finally
        {
            sqlCommandWithdraw.Connection.Close();
        }
    
        decimal withdrawAmm = Convert.ToDecimal(textWithdraw.Text);
        balanceDB = balanceDB - withdrawAmm;
    
        try
        {
            sqlCommandUpdate.Connection.Open();
            sqlCommandUpdate.Parameters["@cardNumber"].Value = Class1.cardNumber;
            sqlCommandUpdate.Parameters["@balanceDB"].Value = balanceDB;
    
            sqlCommandUpdate.ExecuteNonQuery();
            MessageBox.Show(balanceDB +" Successfully Withdrawn");
        }
        finally
        {
            sqlCommandUpdate.Connection.Close();
        }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

... ... ... try { string Tags_collect; SqlDataReader Data1 = cmd.ExecuteReader(); Data1.Read(); lbl_q_title.Text =
Try to open my web-page on vds and then get: We're sorry, but something
try{ String query= select user_name from user; ResultSet rs = queries.performQuery(query); while(rs.next()){ System.out.println(User Name
try { var orderedListOfRfidTags = uow.RfidTags.ToList().OrderBy(t => int.Parse(t.Number)); return View(orderedListOfRfidTags); } catch { var
try { // CompareRecord record = new CompareRecord(); Connection conn = new CompareRecord().getConection(eliteddaprd,eliteddaprd,192.168.14.104,1521); ResultSet
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
Try the following code public enum Color { Blue=1, Red=2, Green=3 } public List<Color>
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals
Try as I might I cannot get my head around what the IteratorIterator class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.