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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:58:10+00:00 2026-06-03T06:58:10+00:00

Can anyone tell me from the code what’s wrong in the code? The lbl

  • 0

Can anyone tell me from the code what’s wrong in the code?

The lbl text should show “Incorrect Username/Password” if the Username and Password do not match.

Code:

Protected Sub btnLogin_Click(sender As Object, e As System.EventArgs) Handles btnLogin.Click

        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Brian\Documents\Visual Studio 2010\WebSites\PetLandia\App_Data\db.mdb")
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [User] where Username=? and Password=?", conn)

        cmd.Parameters.AddWithValue("@Username", txtLogin.Text)
        cmd.Parameters.AddWithValue("@Password", txtPassword.Text)




        If (String.IsNullOrEmpty(txtLogin.Text)) Or (String.IsNullOrEmpty(txtPassword.Text)) Then

            lblLoginError.Text = "One or more fields are empty. Please fill in all the fields"
            lblLoginError.Visible = True

        Else

            conn.Open()
            Dim read As OleDbDataReader = cmd.ExecuteReader()

            Try

                If read.HasRows Then

                    While read.Read()

                        If txtLogin.Text = read.Item("username").ToString And txtPassword.Text = read.Item("password").ToString Then


                            Dim tUsername As String = read.Item("Username").ToString

                            Session("Username") = tUsername
                            Response.Redirect("Default.aspx")


                        End If
                    End While
                End If

                read.Close()
            Catch ex As Exception
                Response.Write(ex.Message())
                lblLoginError.Text = "Incorrect Username/Password."
                lblLoginError.Visible = True

            Finally
                conn.Close()
            End Try


        End If

    End Sub
  • 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-03T06:58:12+00:00Added an answer on June 3, 2026 at 6:58 am

    You can try this code. This code is without Try Catch block.

        Protected Sub btnLogin_Click(sender As Object, e As System.EventArgs) Handles btnLogin.Click
    
             If (String.IsNullOrEmpty(txtLogin.Text)) Or (String.IsNullOrEmpty(txtPassword.Text)) Then
                lblLoginError.Text = "One or more fields are empty. Please fill in all the fields"
                lblLoginError.Visible = True
    
             Else
                Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Brian\Documents\Visual Studio 2010\WebSites\PetLandia\App_Data\db.mdb")
                Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [User] where Username=? and Password=?", conn)
                cmd.Parameters.AddWithValue("@Username", txtLogin.Text)
                cmd.Parameters.AddWithValue("@Password", txtPassword.Text)
                conn.Open()
                Dim read As OleDbDataReader = cmd.ExecuteReader()     
                        If read.HasRows Then
                           read.Read()
                           Session("Username") = read.Item("Username").ToString
                           read.Close()
                           conn.Close() 'Close connection before Redirecting.
                           Response.Redirect("Default.aspx")    
                        Else
                          read.Close()
                          conn.Close()
                          lblLoginError.Text = "Incorrect Username/Password."
                          lblLoginError.Visible = True
    
                        End If
                End If
            End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me the best way to call FoxPro 9 code from a
Code given below is taken from the stackoverflow.com !!! Can anyone tell me how
I'm trying to remove some deprecated code from a site. Can anyone tell me
Can anyone tell me why I do not get intellisense with this code: var
Can anyone tell me what is wrong with this code? I'm trying to determine
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Can anyone tell me how to get and display the biggest values from a
Can anyone tell me if there is a way to select a video from
can anyone tell me how to generate form dynamically in Dotnet from xml file.
can anyone tell me what is the best way to do something like, from

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.