带有用户类型的登录表单 [英] Login form with usertype
本文介绍了带有用户类型的登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个代码来检查用户是管理员还是收银员,然后将其定向到其他表单
I want a code that will check if the user is admin or cashier and then it will direct to the different form
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If txtUser.Text = "" Or txtPass.Text = "" Then
MessageBox.Show("Please complete the required fields!", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' Connect to DB
Dim conn As New System.Data.OleDb.OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\dbBeastFriend.accdb;Persist Security Info=False"
'Try
Dim sql As String = "SELECT * FROM tblCredentials WHERE username='" & txtUser.Text & "' AND password = '" & txtPass.Text & "'"
Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
'Open Database Connection
sqlCom.Connection = conn
conn.Open()
Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
If sqlRead.Read() Then
txtPass.Text = ""
txtUser.Text = ""
txtUser.Focus()
frmAdminChoices.ShowDialog()
Me.Hide()
Else
' If user enter wrong username and password combination
' Throw an error message
MessageBox.Show("Incorrect Username/Password!", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'Clear all fields
txtPass.Text = ""
txtUser.Text = ""
'Focus on Username field
txtUser.Focus()
End If
'Catch ex As Exception
' MessageBox.Show("Failed to connect to Database", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'End Try
End If
推荐答案
您的SQL正在使用*,您是否获取数据库的每一列.您可以通过以下索引或列名访问数据库的列
Your SQL is using * do you getting every column of the database. You can access the column of the database by either the index or the column name like below
txtUser.Text = sqlRead(3)
txtUser.Text = sqlRead("User")
这篇关于带有用户类型的登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文