如何关闭自定义对话框?
运行主程序之前,调用验证用户名和密码的对话框,验证成功后,可进入主程序,但无法关闭验证对话框。
对话框“确定”按钮的代码如下:
SqlConnection myConnection = new SqlConnection("server=situ;uid=sa;pwd=;database=yhljxc");
myConnection.Open();
SqlCommand cmdSql = new SqlCommand("select Password from yhllogin where username="+"'"+tbxUser.Text+"'",myConnection);
SqlDataReader myReader = cmdSql.ExecuteReader(CommandBehavior.CloseConnection);
myReader.Read();
if(tbxUser.Text=="" || tbxPassword.Text=="")
{
MessageBox.Show("请输入用户名和密码!");
}
else if (myReader["Password"].ToString()==tbxPassword.Text.ToString())
{
MainWindow myWin=new MainWindow();
myWin.Show();
myReader.Close();
myConnection.Close();
this.Close();
}
else
{
MessageBox.Show("请输入正确的用户名和密码!");
myReader.Close();
myConnection.Close();
}
}
执行this.Close()后,主程序也退出。如何解决。