我正在使用 visual basic studio 和 mysql 数据库进行学校项目。在这个项目中有不同类型的用户(经理,员工)。我需要的是,当用户通过他/她的用户名和密码登录系统时,程序将从 mysql 数据库中检查“角色”列,如果用户是经理,则确定该用户角色是(经理还是员工)它将登录到经理表单,否则它将转到员工的表单
这是我的代码的一部分:
Try
MySqlConn.Open()
Dim Query As String
Query = "Select * from etdsql.employeeinfo where Username ='" & UNameTextBox.Text & "' and password = '" & PswrdTextBox.Text & "' "
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
Dim count As Integer
count = 0
While Reader.Read
count = count + 1
End While
If count = 1 Then
MessageBox.Show("You are loged in successfuly")
ETDManager.Show()
Me.Hide()
Else
MessageBox.Show("Username and password are not correct")
End If
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
最佳答案
dim role as string
While Reader.Read
count = count + 1
role = Reader("Role") //This is the column's name in your db
End While
If count = 1 Then
MessageBox.Show("You are loged in successfuly")
if role = "Manager" Then
ETDManager.Show()
else
ETDEmployee.Show() //This is the name of your Employee form
end if
Me.Hide()
Else
MessageBox.Show("Username and password are not correct")
End If
```
it could be something like that, but you will have to change the names of the column in the database and the name of the form by the names you have in your project
关于mysql - 如何通过查看数据库中的角色列以经理或员工身份登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55555864/