【发布时间】:2019-10-01 01:53:46
【问题描述】:
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Enter Credential", MsgBoxStyle.Exclamation)
End If
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim cmd As New OleDbCommand("select count (*) from Admin where username = ? and password = ?, connection")
cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = txtPassword.Text
cmd.Parameters.AddWithValue("@2", OleDbType.VarChar).Value = txtUsername.Text
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
If (count > 0) Then
MsgBox("Login Succeed", MsgBoxStyle.Information)
Else
MsgBox("Account not found check credentials", MsgBoxStyle.Critical)
End If
End Sub
End Class
请任何人帮助我处理此代码... 这是用于登录表单
【问题讨论】:
-
您将连接作为 SQL 命令字符串的一部分传递...
OleDbCommand("select count (*) from Admin where username = ? and password = ?, connection")应该是OleDbCommand("select count (*) from Admin where username = ? and password = ?", connection)