Reputation: 31
I'm Using C Sharp
I Get This error after running the debugger to see wat is wrong with the code:
{"There is no row at 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;
Upvotes: 0
Views: 2573
Reputation: 28687
for (int n = 0; 0 < thisDataSet.Tables["Login"].Rows.Count; n++)
Your for loop's condition checks if zero is less than the row count, which means that your loop will run indefinitely (or until you access a non-existent index). You probably mean to check if n
is less than the row count:
for (int n = 0; n < thisDataSet.Tables["Login"].Rows.Count; n++)
Upvotes: 2
Reputation: 29668
Your loop if flawed:
for (int n = 0; 0 < thisDataSet.Tables["Login"].Rows.Count ; n++)
Shouldn't that be:
for (int n = 0; n < thisDataSet.Tables["Login"].Rows.Count ; n++)
Upvotes: 0