Search code examples
c#databasedatareader

unable to read data from the Reader


I am trying to display the data but from the Reader but is not reading it. When I debug the code using step over / F10 it skips this line

trackCollection.Add(track);

and goes straight to this one:

Reader.Close();

Also, I added an exception at the end to see what's going on but it skips that too and goes to return and returns 0 records. Whereas the records are over 50k records.

Exception Code:

catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        return trackCollection;
    }
}

Any help as to why it's not reading data from the reader and how I can get it to work would be great :) thanks .


Solution

  • There may be 50k records in the data source, but the query you executed returns 0 of them. The code inside the while block is skipped because dataReader.Read() returns false.