Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I check if a user has a certain role in their profile
#2
This is what I've tried so far, and it's not working as intended:

[code2=vbnet]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[/code2]

I have set the initial Enabled property of the menu item (TSMenuItemOptions) to Disabled and it works okay. When the code gets executed, I see in the Text Visualizer during debugging that the proper user's level is being pulled from the DB. This results in the first line of the Select Case being evaluated and the menu item enabled. But after that, it stays enabled even when the entire application is closed and reopened.

Am I doing something wrong?
//Kismet


Messages In This Thread
Re: How do I check if a user has a certain role in their pro - by kismetgerald - 11-08-2012, 02:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Auto-generating Drop Menus from User Input MadManMallard 2 12,537 09-17-2014, 09:41 AM
Last Post: brandonio21
  How can I set profile for a user??? mnxford 5 20,824 04-12-2013, 06:31 PM
Last Post: brandonio21
  Computer User vbcodegeek 6 22,418 11-01-2011, 06:01 PM
Last Post: openeXpressions

Forum Jump:


Users browsing this thread: 1 Guest(s)