I have a form with two textboxes and one Login button, the textbox for the username is called txtUsername, and the textbox for the password is called txtPasswd, with the button being btnLogin. I have inserted a username and password into my database called accountinfo, and now I would like to login and show a specific form(being frmProduct, if the user successfully logs in) if their login matches any login in my database, and if it doesn't match any login in the database, a msgbox is shown saying "Oops! The requested username does not exist in the database!" I'm stuck on how to set this up properly, here's what I have tried so far.
Imports MySql.Data.MySqlClient
Public Class frmLogin
Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ServerString As String = "Server=localhost:8080;User Id=root;Password=;Database=accountinfo"
Dim SQLConnection As MySqlConnection = New MySqlConnection
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Dim dbconnection As MySqlConnection
Dim cmd As MySqlCommand = New MySqlCommand
Dim reader As MySqlDataReader
dbconnection.Open()
cmd.CommandText = "SELECT Status FROM accountinfo WHERE UserName = ?UserName AND Password = ?Password"
cmd.Parameters.Add(New MySqlParameter("?UserName", txtUsername.Text))
cmd.Parameters.Add(New MySqlParameter("?Password", txtPasswd.Text))
cmd.Connection = dbconnection
reader = cmd.ExecuteReader
dbconnection.dispose()
If reader.HasRows() Then
MessageBox.Show("Login successful!", "Welcome")
frmProduct.Show()
Else
MessageBox.Show("Oops! Login unsuccessful!")
End If
End Sub
End Class