再会,
我需要一些帮助。我正在尝试查询我的 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