I need to work with username on any other form in the application. I did the following login form but I am not sure how can I send useraname to the others forms. Any tips?
Thread th;
public void openMainForm(object obj)
{
Application.Run(new MainForm());
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conLogin = new SqlConnection(conString);
SqlCommand sqlLogin = new SqlCommand(sqlString,conLogin);
SqlDataReader dr;
conLogin.Open();
dr = sqlLogin.ExecuteReader();
while (dr.Read())
{
if (txtUser.Text.Equals(dr[0].ToString()) && txtPassword.Text.Equals(dr[1].ToString()))
{
this.Close();
th = new Thread(openMainForm);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
else
{
MessageBox.Show("Invalid Data", "Invalid Username/Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Clear();
txtPassword.Clear();
txtUsername.Focus();
}
}
conLogin.Dispose();
}