469,575 Members | 1,291 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Efficient use of DataReader

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());
}

Sep 19 '06 #1
3 1300
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.

--
I hope this helps,
Steve C. Orr
MCSD, MVP, CSM
http://SteveOrr.net
<de*******@yahoo.comwrote in message
news:11*********************@d34g2000cwd.googlegro ups.com...
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());
}

Sep 19 '06 #2
Then why bother using a datareader? Get all the data into a datatable to
begin with.

<de*******@yahoo.comwrote in message
news:11*********************@d34g2000cwd.googlegro ups.com...
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());
}

Sep 19 '06 #3
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:Ok**************@TK2MSFTNGP05.phx.gbl...
Then why bother using a datareader?
I was wondering that too...! :-)
Sep 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Yasutaka Ito | last post: by
6 posts views Thread by Ravi | last post: by
20 posts views Thread by Mark | last post: by
2 posts views Thread by Andrei Pociu | last post: by
1 post views Thread by Brent | last post: by
7 posts views Thread by Diffident | last post: by
3 posts views Thread by Johnny Jörgensen | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.