views:

83

answers:

2

When should I use DataSet instead of DataReader?

When I must use DataSet instead of DataReader?

When should I use data in a disconnected fashion?

When I must use data in a disconnected fashion?

N.B. I am not asking which is better. I need to know the appropriate scenarios of the use of DataSet. I am programming in .net for couple of years but I never seriously needed it.

A: 

A DataSet holds all of the needed data records in memory, whereas a DataReader reads records from a data connection one record at a time.

DataSets are commonly filled with data using DataReaders.

Use a DataReader when you need a high-performance, forward-only reader.

Use a DataSet when you need to do something that requires all of the data to be present at once, such as serialization or passing data between tiers. However, as others have pointed out, using List<T> rather than a DataSet object provides better separation of concerns between tiers.

See http://articles.sitepoint.com/article/dataset-datareader and http://msdn.microsoft.com/en-us/magazine/cc188717.aspx for more info on this.

Robert Harvey
It should be noted that DataSets can be loaded with DataReaders (I don't know a use case outside of proving that it can be done).
jrcs3
That could also be done with List<T>.
JMSA
I think you have it backwards. DataReaders are forward only and higher performance than DataSets, which are more focused on holding all of the data at once. I also prefer sending List<T> between tiers. It keeps the domains more cleanly segregated.
Andy_Vulhop
@codemonkey4hire: Yep, you're right. Got it backwards, fixing...
Robert Harvey
@codemonkey4hire: fixed, and made mention of List<T>.
Robert Harvey
+2  A: 

One scenario, When you want to pass data from one layer to another layer of your application you could use dataset. For more information Dataset and DataReader

Neil
That could be done with List<T>.
JMSA
I agree if you change "should" to "could". @JMSA has points out a valid alternative.
jrcs3
Yes thats true then in that case use DataReader to populate your list
Neil