dimanche 4 juillet 2021

c# else statement never run

I'm using this code to check the user name and password but the problem is the (if) statement execute when user and pass is true but when both is wrong or one is wrong else never run and never show the MessageBox..

help please thank you..

    private void LoginBTN_Click(object sender, EventArgs e)
    {
       using(SqlConnection sq=new SqlConnection(connect))
        {
            
            SqlCommand cmd = new SqlCommand("select * from Users where _User =@User AND _Password=@pass");
            sq.Open();
            cmd.Parameters.AddWithValue("@User", UerTXT.Text);
            cmd.Parameters.AddWithValue("@pass", PassTXT.Text);
            cmd.Connection = sq;
            SqlDataReader SQreadr = cmd.ExecuteReader();

           
         
            while (SQreadr.Read())
            {
                if ((string)SQreadr[1]==UerTXT.Text && (string)SQreadr[2] == PassTXT.Text)
                {
                   
                    string Name = SQreadr[1].ToString();
                    LitForm lf1 = new LitForm(Name);
                    lf1.Show();
                   
                }
               else
                {
                    UerTXT.Text = "";
                    PassTXT.Text = "";
                    MessageBox.Show("check your username and password");
                }

            }
         
        }
    }

Aucun commentaire:

Enregistrer un commentaire