Click here to Skip to main content
15,883,901 members
Home / Discussions / C#
   

C#

 
GeneralRe: Code not splitting for login form. C# Pin
Richard MacCutchan11-Nov-19 1:50
mveRichard MacCutchan11-Nov-19 1:50 
AnswerRe: Code not splitting for login form. C# Pin
OriginalGriff11-Nov-19 1:32
mveOriginalGriff11-Nov-19 1:32 
NewsRe: Code not splitting for login form. C# Pin
Eddy Vluggen11-Nov-19 3:20
professionalEddy Vluggen11-Nov-19 3:20 
QuestionQuestion Pin
Member 1450924010-Nov-19 1:39
Member 1450924010-Nov-19 1:39 
QuestionRe: Question Pin
Richard MacCutchan10-Nov-19 1:44
mveRichard MacCutchan10-Nov-19 1:44 
AnswerRe: Question Pin
OriginalGriff10-Nov-19 1:48
mveOriginalGriff10-Nov-19 1:48 
AnswerRe: Question Pin
Eddy Vluggen10-Nov-19 1:51
professionalEddy Vluggen10-Nov-19 1:51 
QuestionHow to disable other buttons based on user role login Pin
Member 146022408-Nov-19 22:05
Member 146022408-Nov-19 22:05 
Hi forum members,

I am very new beginner in programming. I am trying to develop a window application form database project. The database has four different user roles that log in at the UserLogin form (i.e. Admin, Accountant, HR and ReadOnly).

When any of the users logs in, they are all redirected to a Dashboard with four link buttons named; Admin, Accountant, HR and ReadOnly; that open to the individual's access pages. Now, with the exception of the Admin, I want all the other roles buttons on the Dashboard disabled except the button of the role user who logged in.

I will appreciate if someone could assist me modify my code in order to achieve the expected success.
Below is a section of my login code:-

C#
<pre>        private void loginButton_Click(object sender, EventArgs e)

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

            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();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Welcome to the Dashboard");
                this.Hide();
                
                dashboard.Show();

                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);
                con.Close();
            }       
            else
            {
                MessageBox.Show("Access Denied!!");
                Application.Exit();
            }
            con.Close();
        }


modified 9-Nov-19 4:16am.

AnswerRe: How to disable other buttons based on user role login Pin
OriginalGriff8-Nov-19 22:30
mveOriginalGriff8-Nov-19 22:30 
AnswerRe: How to disable other buttons based on user role login Pin
Richard MacCutchan8-Nov-19 22:53
mveRichard MacCutchan8-Nov-19 22:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes9-Nov-19 10:21
professionalMycroft Holmes9-Nov-19 10:21 
GeneralRe: How to disable other buttons based on user role login Pin
OriginalGriff9-Nov-19 10:35
mveOriginalGriff9-Nov-19 10:35 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan9-Nov-19 20:53
mveRichard MacCutchan9-Nov-19 20:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes10-Nov-19 10:08
professionalMycroft Holmes10-Nov-19 10:08 
AnswerRe: How to disable other buttons based on user role login Pin
BillWoodruff9-Nov-19 20:31
professionalBillWoodruff9-Nov-19 20:31 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 2:01
professionalEddy Vluggen10-Nov-19 2:01 
GeneralRe: How to disable other buttons based on user role login Pin
BillWoodruff10-Nov-19 4:24
professionalBillWoodruff10-Nov-19 4:24 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 6:16
professionalEddy Vluggen10-Nov-19 6:16 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan10-Nov-19 4:49
mveRichard MacCutchan10-Nov-19 4:49 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 6:14
professionalEddy Vluggen10-Nov-19 6:14 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan10-Nov-19 6:20
mveRichard MacCutchan10-Nov-19 6:20 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 7:32
professionalEddy Vluggen10-Nov-19 7:32 
GeneralRe: How to disable other buttons based on user role login Pin
BillWoodruff10-Nov-19 6:47
professionalBillWoodruff10-Nov-19 6:47 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 7:45
professionalEddy Vluggen10-Nov-19 7:45 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 8:01
professionalEddy Vluggen10-Nov-19 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.