I don't have much knowledge about databases and SQL, so I am trying to get help here, I know this should be basic knowledge though, but as a newbie I am not sure where to start.
I am having a problem figuring out how to get a specific value from datatable, I already have the ID
in form2 using this code:
cmd = new SqlCommand("select UserID from Users where UserName='" + textBox1.Text + "' and UserPassword='" + textBox2.Text + "'", cn);
object result = cmd.ExecuteScalar();
if (result != null)
{
loginresult = 1;
LoginUserID = Convert.ToInt32(result);
AdminRights = ???; //how can I get this value from datatable?
UserRights = ???; //how can I get this value from datatable?
this.Close();
}
Now in form1, I want to get the value of AdminRights or UserRights by ID, I have this code,:
private void button7_Click(object sender, EventArgs e) // Button to Form2
{
Form2 win_form2 = new Form2();
win_form2.ShowDialog();
if (win_form2.loginresult == 1)
{
label4.Text = string.Format("User ID: {0}", win_form2.LoginUserID.ToString()); // Gets and places specific user ID
if (win_form2.UserRights = 0 && win_form2.AdminRights = 1) // Check if the ID has AdminRights
label5.text = string.Format("Rights: {0}", "Admin") // If true, do the following
else if (win_form2.UserRights = 1 && win_form2.AdminRights = 0) // Check if the ID has UserRights
label5.text = string.Format("Rights: {0}", "User") // If true, do the following
}
}
My datatable:
- UserID (PK 1,1)
- UserName (string)
- UserPassword (string)
- AdminRights (int) (value could be 0 or 1, and can't be the same value as UserRights)
- UserRights (int) (value could be 0 or 1, and can't be the same value as AdminRights)
So at the end, how can I access to the datatable and get UserRights and AdminRights values in form2?
NOTE: I understand that I have very dangerous code regarding passwords and SQL injection, for now I only want it to work.