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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:15:35+00:00 2026-06-04T15:15:35+00:00

I have a C# application that submits information to an Access database. I fill

  • 0

I have a C# application that submits information to an Access database. I fill in three required boxes , and click “Submit”. The script should respond in the following manner when the use clicks the button:

Step 1. Look into database Table A, to see if the value in textBox1 exists in the database.

Step 2. If the value exists, add the values of textBox1, textBox2, and textBox3 into database Table B columns, respectively.

Step 3. If any one of the three text boxes are left blank, display a message.

Step 4. If the value in textBox1 is not in the database table, display a message. (eventually, I plan the replace the message with a default population of the database fields)

THE PROBLEM: When I run the program, in any of the above cases, the result is Step number 4 above. It seems to skip the first “if” statement, and jumping right to the “else” outcome.

Any help resolving this, would be greatly appreciated! The “Private Void “code is below.
Thanks in advance.


private void button1_Click(object sender, EventArgs e)
{
     OleDbCommand cmd = new OleDbCommand("select * from script_Orders where cust_Name = @UserID", vcon);
     OleDbParameter param = new OleDbParameter();
     param.ParameterName = "@UserID";
     param.Value = textBox1.Text;
     cmd.Parameters.Add(param);
     OleDbDataReader reader = cmd.ExecuteReader();
     {    
         if (reader.HasRows)
         {
             if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
             {
                 MessageBox.Show("You must fill in all fields.");
                 return;
             }
             else
             {
                 OleDbCommand dbCommand;
                 OleDbDataReader dbReader;
                 new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Search\Database.accdb");
                 dbCommand = new OleDbCommand("select count(*) as Record_Count from script_received", vcon);
                 dbReader = dbCommand.ExecuteReader();

                  if (dbReader.Read() == true)
                      rowCount = dbReader["Record_Count"].ToString();
                  else
                      return;

                  var date = DateTime.Now.ToString("MM/dd/yyyy");
                  {
                      using (OleDbCommand command = new OleDbCommand("INSERT INTO script_Received (script, qty, emp_id, received_Date) VALUES (@script,@qty,@emp_Id,@rec_date)"))
                      {
                          command.CommandType = CommandType.Text;
                          command.Parameters.Add("@script", OleDbType.Integer).Value = textBox1.Text;
                          command.Parameters.Add("@qty", OleDbType.VarChar).Value = textBox2.Text;
                          command.Parameters.Add("@emp_id", OleDbType.VarChar).Value = textBox3.Text;
                          command.Parameters.Add("@rec_date", OleDbType.Date).Value = date;
                          command.Connection = vcon;
                          command.ExecuteNonQuery();
                      }
                      this.textBox1.Clear();
                      this.textBox2.Clear();
                      this.textBox1.Focus();
                  }
             }
        }
        else
        {
            MessageBox.Show("The value of textBox1  is not in the orders table");
            return;
        }
    }
} 
  • 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-06-04T15:15:37+00:00Added an answer on June 4, 2026 at 3:15 pm

    If it jumps to the else of if(reader.HasRows) without throwing any exceptions, then reader must not be null, and it’s HasRows property must be false. That means your query executed successfully but returned no rows.

    You might try running the select statement by hand, which might help you understand what’s wrong. Most likely, you’re typing something in the textbox that doesn’t match any of the cust_name values.

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

Sidebar

Related Questions

In my iOS application I have made a form that should submit data into
I have built a blackberry application that allows a user to fill in information
I have application that brings response via Ajax and creates 5-20 new jQuery click
I'm writing a Catalyst application that's required to have a fairly short session expiration
I have application that generates a lot of numbers and writes them to table
I have application that needs to load local html file if user is offline,
I have application that is working in popup. Is there a easy way to
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in

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.