连接尝试显示"enter valid username and password"



当我使用 Access 中的用户名和密码运行程序时,它仍然显示:

输入有效的用户名和密码

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = Nothing Or TextBox2.Text = Nothing Then
MsgBox("Enter Username and password", MsgBoxStyle.Exclamation
)
Else
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim cmd As New OleDbCommand("select count(*)from login where Username and Password=?", connection)
cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = TextBox1.Text
cmd.Parameters.AddWithValue("@2", OleDbType.VarChar).Value = TextBox2.Text
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
cmd.Dispose()
connection.Close()

If (count > 0) Then
MsgBox("Login Sucessful", MsgBoxStyle.Information)
Else
MsgBox("please enter valid username and password", MsgBoxStyle.Critical)
End If
End If
End Sub
End Class

尝试使用有效的语法:

"select count(*) from login where Username=? and Password=?"

这是你的代码吗?连接到数据库时出现问题吗?

Dim cmd As New OleDbCommand("select count(*)from login where Username=@1 and Password=@2", connection)
cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = TextBox1.Text
cmd.Parameters.AddWithValue("@2", OleDbType.VarChar).Value = TextBox2.Text

相关内容

最新更新