how to hide main form before login?
i amd developing windows application using C#. i want to add login form to my project so that i can only see the main form after i successfully loged in.
so how can i do that. the name of my main form is: hrmainfrm
my login code is:
Code:
private void vblogin_Click(object sender, EventArgs e)
{
dbcon.Close();
dbcon.Open();
string qry;
SqlDataReader dr;
qry = "select username,password from userstbl where username='" + txtuserid.Text + "' and password='" + txtpwd.Text + "'";
SqlCommand cmd = new SqlCommand(qry, dbcon);
dr = cmd.ExecuteReader();
if (dr.Read())
{
//what to do here if login is success
}
else
{
lblerr.Text = "Enter valid UserName/Password";
}
dbcon.Close();
}
i am beginner please help me
Re: how to hide main form before login?
The main form gets created and displayed in the Main method, which you'll find in the Program.cs file. You simply display your login dialogue there by calling ShowDialog and use the DialogResult it returns to decide whether to display the main form or not. You then don;t need to call Close on the login dialogue. You just set its DialogResult property. Use OK for a successful login and Cancel otherwise.