vb.net - 连接尝试显示“输入有效的用户名和密码”
问题描述
当我使用 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=?"
推荐阅读
- reactive-programming - 是否可以将任意多个定时 Flux 合并为一个?
- django - DRF:如何获得选择的详细名称?
- html - Bootstrap 3.0.3 词缀 - 内容不在固定位置并移动到其他内容之上
- c# - 无法在 .net 核心中使用 WCF WSHttpBinding
- c++ - 可变参数模板:整数参数到 lambda 的完美转发
- python - Python3修剪关联数组中的所有数据
- firebird - 将 .DBF 文件迁移到 Firebird 2.5:如何使用不同 DBRMS 的 UNION 创建查询
- angular - HighChart中没有Y轴的散点气泡图
- html - 在 IOS 设备上,固定元素在滚动时被下部元素覆盖
- python - 如何更改字符串的替代字母的大小写