I have a MenuStrip in my Windows Form Application which Contains MenuItems.
I want to check some condition and disable the visibility of MenuItems in the MenuStrip bar. Suppose Normal User is accessing the application ,then Some MenuItems will be hidden and if Admin user is accessing the application then all MenuItems should be visible.
I try This code but it doesn't work :
- public Visite(string username)
- {
- InitializeComponent();
- label1.Text = username;
- using (SqlConnection con = new SqlConnection("Data Source=ADMIN-PC\\SQLEXPRESS;Initial Catalog=timar;Integrated Security=True"))
- {
- con.Open();
- bool UserIsAdmin = true;
- using (SqlCommand cmd = new SqlCommand("select * from [User] where Role =@Role", con))
- {
- cmd.Parameters.AddWithValue("@Role", "Admin");
- UserIsAdmin = (int)cmd.ExecuteScalar() > 0;
- }
- if (UserIsAdmin == false)
- {
- utilisateurToolStripMenuItem.Visible = false;
- }
- else
- {
- utilisateurToolStripMenuItem.Visible= true;
- }
- con.Close();
- }
- }

Ranjit PowarRank #553 · 4.4K reputationPosted Jun 20, 2016, 2:34 AM EDT
Ranjit PowarRank #553 · 4.4K reputationPosted Jun 20, 2016, 1:49 AM EDT
Rose Rouge27 reputationPosted Jun 20, 2016, 1:54 AM EDT
Ranjit PowarRank #553 · 4.4K reputationPosted Jun 20, 2016, 2:06 AM EDT
Rose Rouge27 reputationPosted Jun 20, 2016, 2:15 AM EDT
Since this exemple doesn't work , Have you any other idea to do it ?
Ranjit PowarRank #553 · 4.4K reputationPosted Jun 20, 2016, 2:19 AM EDT
Rose Rouge27 reputationPosted Jun 20, 2016, 2:23 AM EDT