0
Good day,如何檢查用戶是否在其個人資料中有特定角色?
我需要一些幫助。我試圖查詢我的MySQL數據庫,看看我的應用程序當前登錄的用戶是否具有某些權限/角色。如果查詢的值確實存在,那麼我想啓用某個菜單項。
我檢查了大部分類似的問題,因爲我輸入了我的問題,但他們主要處理ASP和JSP,因此我更加困惑(因爲我還沒有研究這些問題)。我仍然在學習VB.Net和MySQL。
您的幫助將不勝感激。
這裏是我的代碼 - 什麼我沒有做正確的?:
Public Sub checkAccessLevel()
Dim dbConn As New MySqlConnection(String.Format("Server={0};Port={1};Uid={2};Password={3};Database=parts", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password))
Dim dbQuery As String = "SELECT Level FROM users WHERE username = '" & FormLogin.TextBoxUsername.Text & "'"
Dim dbAdapter As New MySqlDataAdapter(dbQuery, dbConn)
Dim dbData As MySqlDataReader
Try
dbConn.Open()
dbData = dbAdapter.SelectCommand.ExecuteReader
dbData.Read()
While dbData.Read
Select Case UCase(dbData(0).ToString)
Case Is = "Admin"
TSMenuItemOptions.Enabled = True
Case Is = "Manager"
TSMenuItemOptions.Enabled = True
Case Is = "User"
TSMenuItemOptions.Enabled = False
End Select
End While
dbData.Close()
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
Finally
dbAdapter.Dispose()
dbConn.Close()
End Try
End Sub