我正在尝试创建一个简单的访问数据库登录表单,并在运行时收到上述错误。仅当用户组合正确时才会发生这种情况。如果登录不正确,则会显示无效消息。但是,如果我提供正确的凭据,则会引发此错误。有人可以告诉我这个错误的确切含义。它提到“从字符串“BT”到类型“布尔”的转换无效。其中“BT”是正确的用户名。
Private Sub login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
' If txtLogin.Text = "1" And txtPassBox.Text = "1" Then
' Form2.Show()
' Me.Hide()
' Else : MsgBox("Sorry, That combination is not recognised.", MsgBoxStyle.Critical, "Invalid Data Supplied")
' End If
Dim user As String
Dim password As String
user = txtLogin.Text
password = txtPassBox.Text
If Me.UserTableAdapter.ScalarQueryLogin(user, password) Then
MessageBox.Show("You have logged in")
Else
MessageBox.Show("You have supplied the wrong combo")
End If
End Sub
sql查询:
SELECT [User], [Password]
FROM [User]
WHERE ([User] = ?) AND ([Password] = ?)