2013-03-01 1 views
0

J'utilise C de SharpIl y a pas de ligne à la position 5

I Get Cette erreur après l'exécution du débogueur pour voir wat est le problème avec le code:

{ "Il n'y a pas de ligne à la position 5 . "} {System.Exception System.IndexOutOfRangeException}

public DataSet FindData(string ID, string pass) 
    { 
     InitializeConnection(); 
     m_oCn.Open(); 
     DataSet thisDataSet = new DataSet(); 
     DataSet foundDataSet = new DataSet(); 
     try 
     { 
      m_oDA.Fill (thisDataSet, "Login"); 
      for (int n = 0; 0 < thisDataSet.Tables["Login"].Rows.Count ; n++) 
      { 
       if (thisDataSet.Tables["Login"].Rows[n]["UserName"].ToString() == ID) 
       { 
        if (thisDataSet.Tables["Login"].Rows[n]["Password"].ToString() == pass) 
        { 
         m_oDA.Fill(foundDataSet,n,1,"Login"); 


        } 
       } 
      } 
     } 
     catch 
     { 
     } 
     finally 
     { 
      m_oCn.Close(); 
      m_oCn = null; 
     } 
     return foundDataSet; 

Répondre

2
for (int n = 0; 0 < thisDataSet.Tables["Login"].Rows.Count; n++) 

Votre pour les contrôles de l'état de boucle si zéro est inférieur au nombre de lignes, ce qui signifie que votre boucle fonctionnera indéfiniment (ou jusqu'à ce que vous accédez à un index inexistant). Vous avez probablement l'intention de vérifier si n est inférieur au nombre de lignes:

for (int n = 0; n < thisDataSet.Tables["Login"].Rows.Count; n++) 
+0

Merci OK Je l'obtiens maintenant..THanks pour l'expliquer. (Y) – user2121793

0

Votre boucle si viciée:

for (int n = 0; 0 < thisDataSet.Tables["Login"].Rows.Count ; n++) 

Sho uldn't qui soit:

for (int n = 0; n < thisDataSet.Tables["Login"].Rows.Count ; n++) 
Questions connexes