title: The main menu doesn't load with correct permissions assigned (C#)
body: <p>I'm developing a windows form application with C# and the issue is as follows.</p>
  
  <p>The requirement is to change properties in my main menu items (Ex: Make certain menu strip items invisible, etc.), according to the role of logged-in users (Ex: The main menu of a student shouldn't contain the "Lecturer" menu strip item)</p>
  
  <p>The code for my login form is as follows.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.Data.SqlClient;
  using DBL;
  
  namespace Interfaces
  {
      public partial class frmLogin : Form
      {
          public frmLogin()
          {
              InitializeComponent();
          }
  
          public string UserID;
          public string Password;
          public string Role;
  
  
          private void btnLogin_Click(object sender, EventArgs e)
          {
  
              String SQL = "SELECT * FROM LoginInfo";
  
              string connectionString;
              SqlConnection con;
              connectionString = @"Data Source=DESKTOP-U9V5QGE\CL_HNDCSE_86_16;Initial Catalog=UNIMAP_WAD;Integrated Security=True";
              con = new SqlConnection(connectionString);
              con.Open();
  
              SqlCommand comm = new SqlCommand(SQL, con);
              SqlDataReader sqlDReader = comm.ExecuteReader();
  
              UserID = txtUserID.Text;
              Password = txtPassword.Text;
  
  
              while (sqlDReader.Read())
              {
                  Role = sqlDReader["Role"].ToString();
              }
  
              if (UserID == sqlDReader["UserID"].ToString() &amp;&amp; Password == sqlDReader["Password"].ToString())
              {
  
                  con.Close();
  
                  if (Role == "SuperAdmin")
                  {
                      CurrentCredentials.LoggedInUID = UserID;
                      CurrentCredentials.LoggedInRole = Role;
  
                      frmMainMenu objmainmenu = new frmMainMenu();
                      objmainmenu.Show();
  
  
                  }
                  else if (Role == "Admin")
                  {
                      CurrentCredentials.LoggedInUID = UserID;
                      CurrentCredentials.LoggedInRole = Role;
  
                      frmMainMenu objmainmenu = new frmMainMenu();
                      objmainmenu.Show();
  
                      objmainmenu.credentialsToolStripMenuItem.Visible = false;
                  }
                  else if (Role == "StudentCoordinator")
                  {
                      CurrentCredentials.LoggedInUID = UserID;
                      CurrentCredentials.LoggedInRole = Role;
  
                      frmMainMenu objmainmenu = new frmMainMenu();
                      objmainmenu.Show();
  
                      objmainmenu.credentialsToolStripMenuItem.Visible = false;
                      objmainmenu.lecturerToolStripMenuItem.Visible = false;
                  }
  
                  else if (Role == "Lecturer")
                  {
                      CurrentCredentials.LoggedInUID = UserID;
                      CurrentCredentials.LoggedInRole = Role;
  
                      frmMainMenu objmainmenu = new frmMainMenu();
                      objmainmenu.Show();
  
                      objmainmenu.credentialsToolStripMenuItem.Visible = false;
                      objmainmenu.studentToolStripMenuItem.Visible = false;
  
                  }
  
                  else if (Role == "Student")
                  {
                      CurrentCredentials.LoggedInUID = UserID;
                      CurrentCredentials.LoggedInRole = Role;
  
                      frmMainMenu objmainmenu = new frmMainMenu();
                      objmainmenu.Show();
  
                      objmainmenu.credentialsToolStripMenuItem.Visible = false;
                      objmainmenu.lecturerToolStripMenuItem.Visible = false;
  
                  }
                  else
                  {
                      MessageBox.Show("Invalid credentials", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }
  
              }
              else
              {
                  MessageBox.Show("Invalid credentials", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
  
  
          }
  
  
      }
  }
  </code></pre>
  
  <p>Also, using a static class "CurrentCredentials" to store the current users' User ID and Role.
  Resides in the Class Library "DBL".</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data.SqlClient;
  using DBL;
  
  namespace DBL
  {
      public static class CurrentCredentials
      {
          private static string _LoggedInUID;
          private static string _LoggedInRole;
  
  
          public static String LoggedInUID
          {
  
              get
              {
                  return _LoggedInUID;
              }
              set
              {
                  _LoggedInUID = value;
              }
  
          }
  
          public static String LoggedInRole
          {
              get
              {
                  return _LoggedInRole;
              }
              set
              {
                  _LoggedInRole = value;
              }
  
          }
  
      }
  }
  </code></pre>
  
  <p>You may see that I've changed the properties from the Login code itself. I've made changes to the Main menu > menu strip items (private > public), so I can access those from anywhere in the program.</p>
  
  <p>Additionally, just now received this error on the following part of the login screen.</p>
  
  <pre><code>//error
  
  An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
  
  //received from the line
  if (UserID == sqlDReader["UserID"].ToString() &amp;&amp; Password == sqlDReader["Password"].ToString())
  </code></pre>
  
  <p>Your expertise provided in this matter is really appreciated.</p>
  
  <p>Thanks in advance. </p>