繁体   English   中英

为什么我的代码没有读取 if 语句中的下一个条件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM