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

  • Home
  • SEARCH
  • 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 7419219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:01:30+00:00 2026-05-29T08:01:30+00:00

Well im here because i have a problem. i have code that was created

  • 0

Well im here because i have a problem. i have code that was created a while ago. my code is working properly when i a user type the correct username and password. so my problem is when a user insert wrong username and password error message wont show. Here is my code:

MyDs.Clear();
MyDa.SelectCommand = Conn.CreateCommand();
MyDa.SelectCommand.CommandText = 
    "select * from PersonalName where Firstname=@first and Lastname=@last";
MyDa.SelectCommand.CommandType = CommandType.Text;
MyDa.SelectCommand.Parameters.Add("@first", DbType.String, 25, "Firstname").Value = textbox_Username.Text;
MyDa.SelectCommand.Parameters.Add("@last", DbType.String, 25, "Lastname").Value = textbox_Password.Text;

MyDa.Fill(MyDs);
foreach (DataRow item in MyDs.Tables[0].Rows)
{
    if (textbox_Username.Text != item[1].ToString() || textbox_Password.Text != item[3].ToString())
    {
        MessageBox.Show("not connected");
    }
    else
    {
        MessageBox.Show("Connected");
    }
}

Anyone can tell me what is the problem with this code?

  • 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-29T08:01:31+00:00Added an answer on May 29, 2026 at 8:01 am

    Your dataset will be empty if they put in the wrong username. This will be closer to what you want:

    if (MyDs.Tables[0].Rows.Count > 0)
    {
        // you don't need to check username, the SQL query took care of that
    
        if (textbox_Password.Text == item[3].ToString())
            MessageBox.Show("Connected.");
        else
            MessageBox.Show("Failed."); // wrong password
    }
    else
        MessageBox.Show("Failed."); // no such user
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well here's my problem I have three tables; regions, countries, states. Countries can be
Well, I'm gonna be pretty straightforward here, I just have a piece of code
I have been trying to solve this problem for hours (searched here as well
I have a problem when multiple threads try to increase int. Here's my code:
Well i am here writing some constraints for a db I am working on
Well i need some help here i don't know how to solve this problem.
Well, this is my first post here and really enjoying the site. I have
Well, I think I have a very basic doubt here: I'm developing an app
Here is one very interesting problem. I am using SQL Server 2008. I have
I have a template filter that performs a very simple task and works well,

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.