不可天,
我需要一些帮助。我正在尝试查询我的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
答案 0 :(得分:0)
我设法解决了我自己的问题如下;
修改Select Case语句....
ORIGINAL(不正确):
Select Case UCase(dbData(0).ToString)
修改(正确):
Select Case dbData(0).ToString