473,323 Members | 1,551 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,323 software developers and data experts.

DataReader Vs List Class

I have recently joined a company and while looking at the source code I did
find the following:
They were accessing data from database using dataReader and after that
passing it to List Class.
then accessing that data ( i,.e in List Box, dataGrid etc)
I was thinking that there is no need to pass it to List Class. Any
suggestions would be appreciated.

Also they were doing the same with dataSet..passing it to datatable.

Thanks
DNP
Aug 6 '07 #1
3 2815
DNP,

Is this an ASP.NET project? If so, then you can data bind to a data
reader. If this is a Windows Forms project, then placing the items into a
list and binding to that makes sense. I've seen people use data readers to
get data and place them into custom objects because they don't want the
overhead of a DataTable/DataSet or because they prefer to use business
objects.

As far as passing a data set to a data table, that doesn't make much
sense. Can you clarify?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"dotComPaJi" <in**@t.comwrote in message
news:eS**************@TK2MSFTNGP05.phx.gbl...
>I have recently joined a company and while looking at the source code I did
find the following:
They were accessing data from database using dataReader and after that
passing it to List Class.
then accessing that data ( i,.e in List Box, dataGrid etc)
I was thinking that there is no need to pass it to List Class. Any
suggestions would be appreciated.

Also they were doing the same with dataSet..passing it to datatable.

Thanks
DNP

Aug 6 '07 #2
Hi,

"dotComPaJi" <in**@t.comwrote in message
news:eS**************@TK2MSFTNGP05.phx.gbl...
>I have recently joined a company and while looking at the source code I did
find the following:
They were accessing data from database using dataReader and after that
passing it to List Class.
The DataReader is a server side cursor, in other words it keep a connection
open to the DB as long as it exist. This is a no-no in a web project (and
most posibbly in any other scenario).
then accessing that data ( i,.e in List Box, dataGrid etc)
I was thinking that there is no need to pass it to List Class. Any
suggestions would be appreciated.
You could either keep it in a dataset (using DataAdapter.Fill ) or in a
strong typed collection. What you do not want to do is keep it in a Data
Reader for the above mentioned reasons.
Aug 6 '07 #3
I wouldn't say it is a no-no. Holding it beyond the processing of a
page would be a no-no, but if you use it in the context of a single page
being processed, then there isn't a problem. As a matter of fact, for data
binding in ASP.NET, I would say that this is the better way to data bind.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote
in message news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

"dotComPaJi" <in**@t.comwrote in message
news:eS**************@TK2MSFTNGP05.phx.gbl...
>>I have recently joined a company and while looking at the source code I
did find the following:
They were accessing data from database using dataReader and after that
passing it to List Class.

The DataReader is a server side cursor, in other words it keep a
connection open to the DB as long as it exist. This is a no-no in a web
project (and most posibbly in any other scenario).
>then accessing that data ( i,.e in List Box, dataGrid etc)
I was thinking that there is no need to pass it to List Class. Any
suggestions would be appreciated.

You could either keep it in a dataset (using DataAdapter.Fill ) or in a
strong typed collection. What you do not want to do is keep it in a Data
Reader for the above mentioned reasons.

Aug 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nabil m | last post by:
hi , i have been looking around on msdn and google but i still have a couple of oquestions about the difference between a datareader and a dataset - which to use when - 1) do i have to choose...
2
by: Jake S | last post by:
Hi all, Is it possibele to set the datasource of a dropdown list to a datareader? When I try to the only column I receive is a column populated by the datasource name repeated the amount of...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
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...
4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
2
by: Andrew Robinson | last post by:
I am working on a data access layer using a pattern that I see more and more. Define a class that is a data container that is then added to a generic List<>. I am then using this List and support...
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...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
1
by: dotnetnovice | last post by:
Hi dear fellows...i am a newbie in C# and practicing it hardly to learn it. Actually i am reading a table from data base through data reader and displaying it in the gridview and i am doing well...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.