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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:22:57+00:00 2026-05-26T09:22:57+00:00

I have a windows form that takes username and password. It validates it with

  • 0

I have a windows form that takes username and password. It validates it with the database I have created that contains the correct usernames and passwords. So I have implemented a code to verify whether the details entered are proper

Here is my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        myconnection = New SqlConnection("server=PARTH-PC\SQLEXPRESS;uid=sa;pwd=demo;database=fc")
        'you need to provide password for sql server
        myconnection.Open()
        TextBox1.Text = userid
        TextBox2.Text = password



        mycommand = New SqlCommand("select * from student where user id='" & TextBox1.Text & "' and password='" & TextBox2.Text & "')", myconnection)
    Catch ex As Exception
    Finally

    End Try

    Try


        If EOF(1) Then

            MessageBox.Show("Access Denied...Please enter correct password!")

            TextBox1.Text = ""

            TextBox2.Text = ""

            'txtUserName.SetFocus()




        Else
            Txt = "" & " " & UCase$(TextBox1.Text) & ""
            MsgBox("Welcome!!!" & Txt)
            Form2.Show()
        End If
    Catch ex As Exception

    End Try

    myconnection.Close()
     End Sub
  End Class

I am facing a problem in this code..its not working fine ..can someone help me

  • 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-26T09:22:57+00:00Added an answer on May 26, 2026 at 9:22 am

    Without going into the many cons of your code and how you are going about authenticating your users, you could correct your code as follows:

    myconnection.Open();
    mycommand = new SqlCommand("select * from student where user id='" & TextBox1.Text & "' and password='" & TextBox2.Text & "')", myconnection)
    SqlDataReader reader = mycommand.ExecuteReader();
    if(reader != null) 
    {
        if(reader.Read())
        {
            // You found your user. Do what you need to do here.
        }
        else
        {
            // You did not find your user. Do what you need to do here.
        }
    }
    else
    {
        // Something went wrong. You did not find your user. Do what you need to do here.
    }
    

    NOTE: The code is in C#. It shouldn’t be difficult to change it into its VB.NET equivalent

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

Sidebar

Related Questions

I have a Windows Form that takes quite a bit of time to load
I have a C# Windows Form application that contains a menu with this event:
I have a form MainForm which is a Windows Forms form that contains many
I have a windows form application that uses a Shared class to house all
I have a simple Windows Form that hosts property controls at runtime. When the
I have a Windows form application that's consuming web services over https and is
This is the situation. I have a windows form app that uses an access
I have an In-house windows form app that I would like to use Spell
I have a windows form on the main thread and another thread that does
I have a simple .NET 2.0 windows form app that runs off of a

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.