473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1396
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
2
by: hp_1981 | last post by:
Hi, Which one has more performance and speed? using dataset and databinding asp.net controls or building string by SqlDataReader ? the following is my two methods: 1. Using SqlDataReader :...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.