It seems that Login() is your main form, that is why when it is closed, other are automatically closed.. So instead what you can do is,
set the visibility of the form the to false.
public string login()
{
string a = "No";
if (txtuser.Text != "" & txtpass.Text != "")
{
string queryText = "SELECT Count(*) FROM tbllogin " +
"WHERE username = @Username AND pass = @Password";
using (SqlConnection cn = new SqlConnection("Server= localhost;
database=tailoringmng; integrated Security=true"))
using (SqlCommand cmd = new SqlCommand(queryText, cn))
{
cn.Open();
cmd.Parameters.AddWithValue("@Username", txtuser.Text);
cmd.Parameters.AddWithValue("@Password", txtpass.Text);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
frmmainmdi mdi = new frmmainmdi();
a = "Yes";
mdi.A = "Yes";
mdi.Show();
this.Visible = false;
}
else
MessageBox.Show("User Not Found!");
}
}
}
-KR