mysql - 如何通过查看数据库中的角色列以经理或员工身份登录?

标签 mysql vb.net

我正在使用 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/

相关文章:

mysql - 如何在 MySQL 中返回数据透视表输出?

php - 从 MySQL 进行表单日期验证的 AJAX 调用在页面刷新之前不会再次工作

mysql - 如何导入dbf文件数据到phpMyAdmin(Mysql服务器)

php - MySql 查询到 Postgres 查询。 Postgres 不支持 IF 条件

vb.net - service.close()与service.abort()-WCF示例

mysql - 使用服务器资源管理器将 Visual Studio 与 MySQL 数据库连接

vb.net - 这是什么{! } 是指在特定的代码行?

c# - C# 和 VB.Net 之间对象装箱/比较引用的差异

vb.net - 异步事件被触发

vb.net - 带有赋值和 Option Strict 的暗淡声明