I am using An XAMPP locally hosted MySQL server with my login database on. I am trying to compare the entries in the database to the inputs of the TextBoxes in the vb program. However, upon clicking the button the program freezes.
Imports MySql.Data.MySqlClient
Public Class Login
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Parts.User' table. You can move, or remove it, as needed.
'Me.UserTableAdapter.Fill(Me.Parts.User)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Oops ¯\_(ツ)_/¯ " + Err.Description(), MsgBoxStyle.OkOnly, "Enter Value")
Else
Try
Dim connectionString = "server=localhost; userid=root; password=; database=partstest1; CharSet=utf8;"
Dim connDB = New MySqlConnection(connectionString)
Try
connDB.Open()
Dim objCmd = New MySqlCommand
objCmd.Connection = connDB
objCmd.CommandText = "SELECT ID, Username, Password FROM `user` WHERE `Username` = '" + TextBox1.Text + "' and `Password` = '" + TextBox2.Text + "';"
objCmd.CommandType = CommandType.Text
Dim objAdpt = New MySqlDataAdapter
Dim objDS = New DataSet
objAdpt.SelectCommand = objCmd
objAdpt.Fill(objDS)
Console.WriteLine(objDS)
If TextBox1.Text = "admin" Then
'If Access_Level = 0 Then
Me.Hide()
AdminMainMenu.Show()
Else
Me.Hide()
MainMenu.Show()
End If
Catch
MsgBox("Oops " + Err.Description(), MsgBoxStyle.OkOnly, "Failed to Open")
MsgBox("Incorrect login details", MsgBoxStyle.OkOnly)
End Try
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End If
TextBox1.Clear()
TextBox2.Clear()
End Sub
End Class
I tried putting the TextBox.Text equal to a different variable but it had not made a difference. Is my command too complex or have I formatted it wrong maybe? I am pretty new to SQL so any help would be appreciated.