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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:29:08+00:00 2026-05-18T11:29:08+00:00

i am trying to create a login web form , what i need to

  • 0

i am trying to create a login web form , what i need to show a label if the login fails like ” login failed , try again ” , but the problem it doesn’t work

here is my code:

    SqlCommand selectuser = new SqlCommand("select username,password from users where username = '" + TextBox1.Text + "' and password = '" + TextBox2.Text + "'", badersql);
    badersql.Open();
    SqlDataReader dr = selectuser.ExecuteReader();



    while (dr.Read())
    {
        if (dr["username"].ToString() == TextBox1.Text && dr["password"].ToString() == TextBox2.Text)
        {


        }
        else
        {
           Label1.Visible = true;

        }

    }

    dr.Close();

Please Note : i know there is NO parametrized SQL In the code, and that because i don’t need to use them , all the web page is 100% locally so please help me with issue and leave the sql injections 🙂

  • 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-18T11:29:09+00:00Added an answer on May 18, 2026 at 11:29 am

    If no results are returned from the database then your link would never be set to visible, because dr.Read() will return false. Which what is happening to you now.

    What you need to do, as I believe that your query will always return only one result is to just do

            SqlCommand selectuser = new SqlCommand("select username,password from users where username = '" + TextBox1.Text + "' and password = '" + TextBox2.Text + "'", badersql);
            SqlDataReader dr = null;
    
            try
            {
                dr = selectuser.ExecuteReader();
                Label1.Visible = !dr.Read();
            }
            finally
            {
                if (dr != null)
                    dr.Close();
            }
    

    and you should be done.

    now some tips there, you are already doing the filtering in the sql server, so you could just do Select 1 from ... and do command.ExecuteScalar() != null
    If you still want to use a DataReader for other reason, then you should use a try {...} finally { dr.close(); } block to ensure the datareader is not left open when unhandled error happens.

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

Sidebar

Related Questions

I am trying to create a login system for a web application, but I
I am new to zend. I am trying to create login form using zend
I am trying create a small web application that allows a user to login
I am trying to save image to database with Create method. but when try
Ok so I am trying create a login script, here I am using PHP5
I'm trying to create a login system using PHP, and I'm not quite sure
I am trying to create a login page that will send the user to
What I'm trying to do I'm trying to create a Login which is fully
I'm a beginner in php, and I am trying to create a login and
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.

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.