david.godistei 0 Newbie Poster

I am a beginner in C# database developing. I am developing a payroll application with four (4) user roles (i.e. Admin, Accountant, HR and ReadOnly).

There is a Dashboard that displays four buttons that link their respective access pages. Though when logged in based on the user's role, he is directed to the Dashboard successfully. Now, what am expecting are that when the Admin logs in, all buttons on the dashboard should be active. But whenever any of the other users logs in, all other buttons should be disabled, except his.

Below is the code I used; please can someone modify it for me to achieve my expectation?

    private void loginButton_Click(object sender, EventArgs e)

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        SqlCommand command = new SqlCommand();

        string userText = userTextBox.Text;
        string passText = pwdTextBox.Text;

        SqlCommand cmd = new SqlCommand("select role from UsersLogin where UserName='" + userTextBox.Text + "'and Password='" + pwdTextBox.Text + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        if (dt.Rows.Count > 0)
            MessageBox.Show("Welcome to the Dashboard");
            Dashboard dashboard = new Dashboard();

            cmd = new SqlCommand("SELECT Role from UsersLogin where Username=@Username", con);
            cmd.Parameters.AddWithValue("@Username", userText);
            string role = cmd.ExecuteScalar().ToString();
            MessageBox.Show("Welcome " + role);
            MessageBox.Show("Access Denied!!");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.