I am creating a Login Form with a DataBase in Microsoft Access.
The DataBase:
DataBase Photo
I am using Visual Studio 2015 Community Edition.
I have created 2 queries for this:
1) LoginQuery ->
SELECT Username, [Password]
FROM Login
WHERE (Username = ?) AND ([Password] = ?)
2) EmployeeNameQuery ->
SELECT EmployeeName, Username
FROM Login
WHERE (Username = ?)
While executing the code, if I enter both the Username and Password Correctly, I get the following error:
InvalidCastException was unhandled
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "admin" to type 'Boolean' is not valid.
The Error:
Error Photo
Else, for wrong inputs, it works and shows 'Invalid Login!'
What I have tried:
My Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim username As String = UsernameTextBox.Text
Dim password As String = PasswordTextBox.Text
If LoginTableAdapter.LoginQuery(username, password) Then
Dim EmployeeName As String = LoginTableAdapter.EmployeeNameQuery(username)
MsgBox("Login Successful!" & EmployeeName)
Else
MsgBox("Invalid Login!")
End If
End Sub
-> Please explain it in detail because I have been facing this for quite a long time!