Click here to Skip to main content
14,971,215 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ->
VB.NET
SELECT        Username, [Password]
FROM            Login
WHERE        (Username = ?) AND ([Password] = ?)

2) EmployeeNameQuery ->
VB.NET
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:
C#
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:
VB.NET
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!
Posted
Updated 6-Nov-16 4:28am
Comments
[no name] 6-Nov-16 7:45am
   
Explain what in detail? The error message is clear enough. Somewhere you are trying to use the string "admin" as if it were a Boolean value.
Arnav Varshney 6-Nov-16 10:27am
   
But what should I correct so as to make it work @NotPoliticallyCorrect. That's what I meant by please explain in detail.
[no name] 6-Nov-16 15:16pm
   
It's simple. Debug your code and find the place where you are using a string where the code is expecting a Boolean. Then fix it. The stack trace likely tells you exactly where the error is occurring.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900