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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:40:16+00:00 2026-06-15T08:40:16+00:00

I have a login form for my program and it works fine but when

  • 0

I have a login form for my program and it works fine but when i input an username and password that is not in my database, the textbox for the username and password just clears the text and does not show the messagebox that says “incorrect username/password”

Here is my code:

 Dim con As OleDbConnection = New OleDbConnection( _
               "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= UserPass.mdb;")
    con.Open()
    Dim str As String
    str = "SELECT * FROM UserPass WHERE Username='" & txtUsername.Text & "' AND Password='" & txtPassword.Text & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(str, con)
    cmd.Parameters.AddWithValue("user", txtUsername.Text)
    cmd.Parameters.AddWithValue("pass", txtPassword.Text)
    Dim sdr As OleDbDataReader = cmd.ExecuteReader()
    ' It will be case sensitive if you compare usernames here.   
    If sdr.HasRows Then
        If sdr.Read Then
            If txtPassword.Text <> sdr("Password").ToString Or txtUsername.Text <> sdr("Username").ToString Then
                MessageBox.Show(" Incorrect Username/Password. Login Denied ", " Error! ", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show(" You are now Logged In! ", " Welcome! ", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                frmOne.Show()
                Me.Hide()
            End If
        End If
    End If

How can i make my program show a messagebox when i input a username and password that is not in my database?

  • 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-15T08:40:17+00:00Added an answer on June 15, 2026 at 8:40 am

    The Line sdr.HasRows doesn’t look like it would fire. On your select statement it won’t have rows if username and password don’t match.

    Consider changing the code to this :

    If sdr.HasRows Then
        If sdr.Read Then
                MessageBox.Show(" You are now Logged In! ", " Welcome! ", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                frmOne.Show()
                Me.Hide()
        End If
    Else
        MessageBox.Show(" Incorrect Username/Password. Login Denied ", " Error! ", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login form that has Username and password as inputs from user
I'm planning on creating a program that will have a login form and then
I have a usual login form consisting of two input fields, one for login,
i'm thinking about writing a WPF program that would require login and password at
I have this login form on my program in C#, I will be matching
I have a form that I use for login purposes here: <form id =
I have a simple login form that after a correct login slides to the
I have two forms in my program. The first is the login form and
I have a OOP question. I have 3 classes. Program (main class), login form
I have Login form and Main form in my C# WinForm program. When I'm

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.