【发布时间】:2013-12-28 05:33:33
【问题描述】:
为什么当我执行此代码时名为 (Smart_pharmacy) 的表单被关闭:
private void LoginBTN_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=Abdullah-PC;Initial Catalog=SmartPharmacyDB;Integrated Security=True");
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "select userpass from usertab where username = @username";
com.Parameters.Add("@username", usernametxt.Text);
con.Open();
object returnedvalue = com.ExecuteScalar();
if (returnedvalue != null)
{
string returneduserpass = com.ExecuteScalar().ToString();
con.Close();
if (returneduserpass == userpasstxt.Text)
{
Smart_Pharmacy f = new Smart_Pharmacy();
f.Show();
this.Close();
}
else
{
MessageBox.Show("Incorrect username or password !");
}
}
else
{
MessageBox.Show("Incorrect username or password !");
}
}
我希望关闭当前表单并保持表单 (Smart_Pharmacy) 处于打开状态,请帮助。
【问题讨论】:
-
一种可能的解决方案是在 program.cs 中使用该表单进行验证,然后将 Smart_Pharmacy 的实例传递给 Application.Run()。