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 7670577
In Process

The Archive Base Latest Questions

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

Hi having abit of a problem with my code it refuses to do my

  • 0

Hi having abit of a problem with my code it refuses to do my else statement have a global variable set to say attempts = 3

runs the while loop but when i put an invalid pin it basically just doesnt run anything i would appreciate any help possible thanks

while (read.Read())
{
    if (read.HasRows)
{
}
    //If the card isnt confiscated then do this:
    if (((Boolean)(read["confiscated"]) == false))
    {
        string cardnum = read["cardNumber"].ToString();
        string pinnum = read["PIN"].ToString();


        //Compare the results in the table against those put in by the customer
        if (string.Equals(cardnum, cardBox.Text) && string.Equals(pinnum, pinNumber.Text))
        {
            MessageBox.Show("Welcome customer");
            MessageBox.Show("Card Number " + cardnum + " PIN " + pinnum);
            //if the login details match and everything is correct then bring the next form up
            MessageBox.Show("Details are correct");
            pinNumber.Clear();
            //open the options form
            Form optionForm = new optionForm();
            optionForm.Show();
            //hide this form
            this.Hide();
            break;

        }
        else
        {
            if (attempts == 1)
            {
                sqlCommandATM.Parameters["@cardNum"].Value = cardBox.Text;
                sqlCommandATM.Parameters["@confiscated"].Value = true;
                MessageBox.Show("Your card has been confiscated please contact The bank of Glamorgan to resolve the issue");
                pinNumber.Clear();

            }
  • 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:51:17+00:00Added an answer on May 31, 2026 at 3:51 pm

    EDIT
    I’ve tried to understand what you’re doing. I assume you’re trying to authenticate a person by credit card number and PIN against a database, and you’re doing it by getting all the entries from a database table and looping over them to find the one that matches the user input. You want to allow the user to do that three times before locking the credit card.

    I see more than one issue with that: The task of finding the correct row in the table for the user should be left to the database. This is much quicker and less error prone. So if you’d like to do it right, then you should have an SQL statement like:

    int attempts = 0;
    bool success = false;
    
    while (!success && attempts < 3)
    {
        using (SQLCommand exists = new SQLCommand("SELECT ID FROM ... WHERE CCardNo = @cardNo AND PIN = @pin", conn))
        {
            exists.Parameters.AddWithValue("@cardNo", cardNum);
            exists.Parameters.AddWithValue("@PIN", pinnum);
    
            object idObject = (int)exists.ExecuteScalar();
            if (idObject == null || idObject == DBNull.Value)
            {
                attemps++;
            }
            else
            {
                success = true;
            }
    
            if (attempts >= 3)
            {
                // Lock out the user
            }
        }
    }
    
    if (success)
    {
        ...
    }
    

    If you really insist on doing it your way, then please make sure that attempts is initialized properly and is incremented on each login attempt – in your current code, you’d increment it on every row you’re validating against, so you’d lock out every customer who’s not within the first three rows you’re getting from the database.

    Original reply

    OK, you’re reading all data from a DataReader in a while loop:

    while (read.Read())
    {
    

    Then what do the following three lines do? You wouldn’t be here if read.HasRows was false, because read.Read() would have returned false already. The following three lines are pointless and can be removed, leaving only what’s inside the block.

        if (read.HasRows)
        {
        }
    

    The usual way would be:

    if (read.HasRows)
    {
        while (read.Read())
        {
            ...
        }
    }
    

    More is hard to tell as you’re not showing us the complete code – what value does attempts have before the while loop, for example?

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

Sidebar

Related Questions

I'm having a bit of an odd problem while trying to compile some code
I'm having a bit of a problem using FieldOffset correctly with arrays. The code
Having a bit of a problem, Due to the source-control set-up we use, each
I'm having a bit of a problem. I have a datatable in the parent
I'm having a bit of a problem here. We have 2 urls let me
Im having a bit of a problem with this code each time i execute
I'm having a bit of a problem with this code. The program gives me
I'm having a bit of a problem with my code for compiling shaders, namely
I'm having a terrific problem with an implementation of serialscroll. I've set it so
So im having a bit of problem with my code.. It's suppose to cross

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.