mercredi 28 juin 2017

If statement skips the elements except the first one in the for loop. How can I get the right solution fır the other elements?

for (int i = 0; i < dt.Rows.Count; i++)
 {

       if (textBox1.Text == dt.Rows[i]["FIRSTNAME"].ToString().ToLower() && textBox2.Text == dt.Rows[i]["LASTNAME"].ToString().ToLower())

       {
              Main ss = new Main(); // Main is the another form which is seen after the successful enterance.
              ss.Show();
               break;
        }

       else {
       MessageBox.Show("UserName or Password is Wrong");
         }
     }

*I want to create a Windows form application using C# and PL/SQL database. I have a data information which consists of the FİRSTNAME and LASTNAME of the two persons. Because of the for loop, I get both of the success and the failure messages at the same time for the second person's information. When for loop cannot match the second person's information with the first person's information, it shows the failure message. Then it sees right information. So, it returns the true message to me. *

**How can I return the beginning of the if statement to get the all solutions until the end of the database? I put the else statement's codes out of the for loop. I got always the failure message because of the non-existing the if statement to Control the failure.

Shortly, what do I need to do? **

Aucun commentaire:

Enregistrer un commentaire