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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:18:27+00:00 2026-05-28T03:18:27+00:00

im making a mysql sigin form and im trying to use my user table

  • 0

im making a mysql sigin form and im trying to use my user table to control log in access but whenever i type in any random letters it logs into without showing the error that its an invalid username.

This is what i have so far:

   Imports MySql.Data.MySqlClient

    Public Class frmLogin
        Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
            Application.Exit()
        End Sub

        Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
            Dim conn As New MySqlConnection
            Dim myCommand As New MySqlCommand

            Dim myConnString As String
            Dim UserID As String

            myConnString = "server=" & My.Settings.HostIP & ";" _
                & "user id=" & My.Settings.Username & ";" _
                & "password=" & My.Settings.Password & ";" _
                & "database=attendance"

            conn.ConnectionString = myConnString

            Try
                conn.Open()

                myCommand.Connection = conn
                myCommand.CommandText = "SELECT user_bannerid FROM user WHERE BINARY username = ?Username"
                myCommand.Parameters.Add("?Username", txtUsername.Text)

                UserID = myCommand.ExecuteScalar

                conn.Close()

                Dim mainForm As New frmMain
                mainForm.UserID = UserID
                mainForm.connectionString = myConnString
                mainForm.Show()

                Me.Hide()
                Me.Close()
            Catch myerror As MySqlException
                MessageBox.Show("Invalid User. Please Enter Your Correct Username")
                conn.Dispose()
            End Try
        End Sub

        Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.AcceptButton = cmdLogin
            Me.CancelButton = cmdCancel
        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-28T03:18:28+00:00Added an answer on May 28, 2026 at 3:18 am

    This is because you are not testing the value of userid before closing the form.

    You also need to implement using statements to ensure that all disposable items are properly disposed.

    Here is a rewrite that solves both issues:

        Try
            Using conn As New MySqlConnection
                Using myCommand As New MySqlCommand
                    Dim myConnString As String
                    Dim UserID As String
    
                    myConnString = "server=" & My.Settings.HostIP & ";" _
                        & "user id=" & My.Settings.Username & ";" _
                        & "password=" & My.Settings.Password & ";" _
                        & "database=attendance"
    
                    conn.ConnectionString = myConnString
    
                    conn.Open()
    
                    myCommand.Connection = conn
                    myCommand.CommandText = "SELECT user_bannerid FROM user WHERE BINARY username = ?Username"
                    myCommand.Parameters.Add("?Username", txtUsername.Text)
    
                    Dim oUserID As Object
    
                    oUserID = myCommand.ExecuteScalar
    
                    conn.Close()
    
                    If oUserID IsNot DBNull.Value AndAlso Not String.IsNullOrEmpty(oUserID) Then
                        Dim mainForm As New frmMain
                        mainForm.UserID = UserID
                        mainForm.connectionString = myConnString
                        mainForm.Show()
    
                        Me.Hide()
                        Me.Close()
                    Else
                        MessageBox.Show("Invalid User. Please Enter Your Correct Username")
                    End If
                End Using
            End Using
        Catch myerror As MySqlException
            MessageBox.Show("SQL Error" & myerror.ToString())
        End Try
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use both mysqli_real_escape_string and trim together before making a MySQL
I have made a registration program. Making use of mysql database. Can I still
I'm experimenting by making a social network from scratch in PHP/MySQL, but I'm having
I'm modelling MySQL database for an website. I'm now making 'people' table, and deciding
Im making a mysql table which will be holding my blog posts and some
im trying to do a comparison in MYSQL but wish for it to be
I can't look at mysql tables right now...but I don't think '+' is making
When making a MySQL query with no WHERE constraints, most people use WHERE 1
am making function to count rows using WHERE, but i get a mysql error
I'm making a reservation system with one row per reservation in a mySql table.

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.