DataReader Vs List Class

D

dotComPaJi

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
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

dotComPaJi said:
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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top