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

The Archive Base Latest Questions

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

I have implemented a code for user validation in VB.NET. When I enter the

  • 0

I have implemented a code for user validation in VB.NET. When I enter the user name and password in the textboxes of my form, and click the submit button , no message box is displayed even when I have written a code for it . Is there some problem in the try-catch block or am I missing some lines of code?

Can someone point out what’s wrong in this code ?

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles Button1.Click

    If TextBox1.Text = "" Or TextBox2.Text = " " Then
        MsgBox("Enter a user id and password")
    End If
    TextBox1.Text = userid
    TextBox2.Text = password

    Try
        myconnection = New SqlConnection("server=PARTH-PC\SQLEXPRESS;uid=sa;pwd=demo;database=fc")
        'you need to provide password for sql server
        myconnection.Open()

        mycommand = New SqlCommand("select * from student where user id='" &  TextBox1.Text & "' and password='" & TextBox2.Text & "')", myconnection)
        dr = mycommand.ExecuteReader()

    Catch ex As Exception
    Finally



        If (dr IsNot Nothing) Then

            If (dr.Read()) Then

                MsgBox("User is authenticated")
                Form2.Show()



            Else
                MsgBox("Please enter correct username and password")
            End If


        End If

    End Try

    myconnection.Close()
      End Sub
    End Class
  • 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:28:58+00:00Added an answer on May 26, 2026 at 9:28 am

    Use Trim() and Length methods or String.IsNullOrWhiteSpace() (.net framework 4) to check empty or zero length string.

     If TextBox1.Text.Trim().Length = 0 Or TextBox2.Text.Trim().Length = 0 Then
       MsgBox("Enter a user id and password")
       Return 'Terminate this method
     End If
    

    Wrong assignment here,

     Dim userid=TextBox1.Text
     Dim password=TextBox2.Text
    

    Another issue is use of hard coded sql statement.

    myconnection = New SqlConnection("server=PARTH-PC\SQLEXPRESS;uid=sa;pwd=demo;database=fc")
    mycommand = New SqlCommand("select * from student where [user id]=@userid and [password]=@password",myconnection)
    mycommand.Parameters.Add("@userid",SqlDbType.VarChar,30).Value = userid
    mycommand.Parameters.Add("@password",SqlDbType.VarChar,30).Value = password
    
    myconnection.Open()
    dr = mycommand.ExecuteReader()
    Dim isFound as boolean  = false
    if dr.Read() Then
       isFound=true
    End If
    dr.Close()
    myConnection.Close()
    
    if IsFound Then
       MsgBox("User is authenticated")
       Form2.Show()
    Else
       MsgBox("Please enter correct username and password")
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some .NET remoting code where a factory method, implemented in some server
I have implemented this code, but fail at compilation (VC2008 Express Ed.) : Now
FOR ANYONE INTERESTED: I have implemented the code for the behaviour I am looking
I have my application designed with Repository pattern implemented and my code prepared for
I have a signup form on my home page which uses server side validation
My application requires current location of the user. For this I have implemented the
I have a bit of .NET code that retrieves the results from an Oracle
I have implemented some code that will automatically set a UIScrollView's ContentOffset when the
I have a UITextFieldDelegate that does a whole bunch of validation on user input
I have this code for login validation using a Struts2 action class which calls

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.