I use winforms c#
I am trying to get userid from userinfo table and then inserted that userid in another table for this first i try this
updated code
ok i try this
public class Login
{
string email;
string password;
public int userid;
public Login(string UserEmail, string UserPassword)
{
email = UserEmail;
password = UserPassword;
}
public string Logined()
{
con.Open();
cmd = new SqlCommand("SELECT userid from UserInformation WHERE UserEmail='" + email + "'and UserPassword='" + password + "'", con);
cmd.Parameters.AddWithValue("@UserEmail", email);
cmd.Parameters.AddWithValue("@UserPassword", password);
cmd.ExecuteNonQuery();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Categorys obj = new Categorys();
obj.ShowDialog();
while (dr.Read())
{
userid = Convert.ToInt32(dr["userid"]);
}
return msg = "You Are Successfully Login!";
}
else
{
return msg = "Sorry Incorrect Password Or Email!";
}
}
And this for your button_click else if
else if (comboBox1.Text == "Admin.")
{
this.Hide();
string UserEmail = textBox2.Text;
string UserPassword = textBox1.Text;
Login objlogin = new Login(UserEmail, UserPassword);
textBox3.Text = Convert.ToString(objlogin.userid);
MessageBox.Show(objlogin.Logined());
savedid = objlogin.userid;
Categorys obj = new Categorys();
obj.ShowDialog();
con.Close();
}
and in new form i try this on form load for call id
private void Categorys_Load(object sender, EventArgs e)
{
Login_Form l = new Login_Form();
textBox2.Text = Convert.ToString(l.savedid);
}
but this shows 0 in textbox