aron
aron

Reputation: 2886

Idatareader to List

Using Linq is there a more efficient way to do this?

 IDataReader reader = qSeats.ExecuteReader();
            var seats = new List<int>();
            using (IDataReader reader = qSeats.ExecuteReader())
            {
                while (reader.Read())
                {
                    seats.Add(Convert.ToInt32(reader.GetInt32(0)));
                }
            }

I saw: How do I load data to a list from a dataReader? However this is the same code I have above, and it seems like there could be faster ways. Like using Linq or seats.AddRange() or some kind of ToList()

Upvotes: 0

Views: 696

Answers (1)

Habib
Habib

Reputation: 223267

DataReader is read-only, forward-only stream of data from a database. The way you are doing it is probably the fastest.

Using the DataReader can increase application performance both by retrieving data as soon as it is available, rather than waiting for the entire results of the query to be returned, and (by default) storing only one row at a time in memory, reducing system overhead. Retrieving Data Using the DataReader

Upvotes: 1

Related Questions