[英]Why my code is not reading the next condition in if statement
為什么我的代碼不讀取 if 語句中的下一個條件?
MySqlCommand cmd = new MySqlCommand("Select * from admin where Username='" + txtuser.Text + "' and Password='" + txtpass.Text + "' ", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
if (txtuser.Text == dr["Username"].ToString() && txtpass.Text == dr["Password"].ToString())
{
this.Hide();
Form f1 = new Form1();
f1.Show();
}
else if (txtuser.Text != dr["Username"].ToString() && txtpass.Text == dr["Password"].ToString())
{
MessageBox.Show("Incorrect Username!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
clear();
}
else if (txtuser.Text == dr["Username"].ToString() && txtpass.Text != dr["Password"].ToString())
{
MessageBox.Show("Incorrect Password!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
clear();
}
else if (txtuser.Text == "" & txtpass.Text == "")
{
MessageBox.Show("Please Enter Username and Password!", "Message", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else if (txtuser.Text == "" && txtpass.Text != "")
{
MessageBox.Show("Please Enter Username!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
clear();
}
else if (txtuser.Text != "" && txtpass.Text == "")
{
MessageBox.Show("Please Enter Password!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
clear();
}
else if (txtuser.Text != dr["Username"].ToString() && txtpass.Text != dr["Password"].ToString())
{
MessageBox.Show("Incorrect Username and Password!", "Message", MessageBoxButtons.OK,
MessageBoxIcon.Error);
clear();
}
}
在 C# 中的 && 條件的情況下,如果第一個變為假,則將不會驗證下一個條件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.