Efficient use of DataReader

  • Thread starter Thread starter dejavue82
  • Start date Start date
D

dejavue82

Wound't be wise and efficient to copy the rows into a collection list
ArrayList, close the connection and then process the data? (Rather than
do the processing while the connection is still open).


ArrayList data_array = new ArrayList();
while (reader.Read())
{
data_array.Add(reader["some_column"].ToString());
}
 
If you're just doing something quick with the data and only looping through
it once, then no you shouldn't bother going through all the trouble of
loading up RAM with an extra object instantiation that provides no real
value.

However, if you need to loop through that same data multiple times then an
ArrayList might serve as a useful and efficient cache.
 
Then why bother using a datareader? Get all the data into a datatable to
begin with.
 
Back
Top