0

仅供参考,我有表权限和用户。在我的 Users 表中,它有 4 列,即:user_id、username、password、authority_id,在授权表中,它有 2 列:authority_id、authority_level。

我的登录表单要求用户输入他们的用户名和密码。在给出正确的参数后,它应该验证用户是管理员 = 1、护士 = 2 还是医生 = 2。

这是我到目前为止所尝试的:

Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click

    If txtUsername.Text = "" Or txtPassword.Text = "" Then
        MsgBox("Enter UserName and Password Moron")
    Else
        'SQL Query To Get The Details
        Dim myAdapter As New MySqlDataAdapter
        Dim sqlquerry = "Select * From users where username = '" + txtUsername.Text + "' And password= '" + txtPassword.Text + "'"
        Dim myCommand As New MySqlCommand()
        myCommand.Connection = SQLConnection
        myCommand.CommandText = sqlquerry
        'Starting The Query
        myAdapter.SelectCommand = myCommand
        Dim mydata As MySqlDataReader
        mydata = myCommand.ExecuteReader
        'To check the Username and password and to validate the login a
        If mydata.HasRows = 0 Then
            MsgBox("Invalid Login")
        Else
            MsgBox("Welcome " + txtUsername.Text + "!")
            If authority Then
                frmMain.Show()
            Else
                frmMainNurse.Show()
            End If
            Me.Hide()
        End If
    End If
End Sub

请注意,我没有在这一行中添加任何内容:

If authority Then

我不知道如何在 vb.net 中做到这一点。因此,如果有人知道如何做到这一点,我将非常感谢您的帮助。谢谢。

4

1 回答 1

0

在你的 else 部分执行此操作

Else
    Dim authorityid = 0
    While mydata.Read()
        authorityid = mydata.GetInt32("authority_id")   
    End While
    MsgBox("Welcome " + txtUsername.Text + "!")
    If authorityid = 1 Then
       frmMain.Show()
    Else
       frmMainNurse.Show()
    End If
    Me.Hide()
End If
于 2013-01-02T18:53:06.013 回答