문제

I'm using a SqlCeDataReader to read results from a query and add them to a list of objects which may return 0 or many rows.

My code:

while (tourReader.Read())
{
    Tour newTour = TourDBA.RetrieveTour( (int)reader["Id"] );
    if (newTour != null)
        creater.Tours.Add(newTour); 
}

I would ASSUME that since the Select query should return 0 rows, Read() would return false and thus the loop would never be entered. (I know what's in the table for this test instance, and 0 rows is the expected behavior this test.)

Any idea how to get around this? (Using .HasRows also throws an exception.)

One other thing - the connection I'm using in this query is open, and was used in a different SqCeCommand other than the one being executed here before the method comes to this while loop. If that matters...

도움이 되었습니까?

해결책

Check it:

while (tourReader.Read()) // tourReader here
{
    Tour newTour = TourDBA.RetrieveTour( (int)reader["Id"] ); // reader here
    if (newTour != null)
        creater.Tours.Add(newTour); 
}

Are reader and tourReader the same?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top