Which one is better Dataset or DataReader? [Resolved]

Posted by Patel28rajendra under ASP.NET on 3/23/2012 | Points: 10 | Views : 7148 | Status : [Member] | Replies : 7
Hi

Please tell me which one is better for reading data from database


for practical point of view

DataSet or
Darareader ?



Thanks

R D Patel


Responses

Posted by: Jmckamal on: 3/23/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
It depends on your operation. You have to decide based on your situation and for what you are going to utilize that data. As per my experience in many situations I have used both dataset and data reader. Normally what I will do is, before writing code I will think what am I going to do with this data, Whether I am going to manipulate it or just read and show the data. If I am going to manipulate (Edit/update etc) then I will choose dataset otherwise I will go for DataReader.

EX : let's Say.. I have a requirement like this.. in a webpage I have a dropdownlist and based on dropdownlist selection I need to display data inside Gridview with lot of CRUD operation. Now usually we don't edit data which is available inside dropdown, so in that case use DataReader. It loads data faster than the dataset, because you know it is doing only read only operation. Hence performance is also good.


Also I will give you few more tips for you to use DataReader and Dataset , that will help you if you keep it in mind. Those are:

1. DataSets can easily be passed between layers in an application.
2. When you have data that is accessed by a number of users and can reasonably be cached for at least a short period of time, the cache can be used on a DataSet. Caching can have a dramatic impact on the performance of a heavily used application.
3. One of the disadvantage of using a DataReader is that the connection must be open while you are accessing the data.
4. One of the big advantage of using dataset is, It is a database-independent, in-memory data store that enables the developer to directly access all rows and columns of one or many tables that a DataSet can contain.
5. Suppose if you are building a Windows Forms application (or a "Smart Client"), DataSets offer some advantages. Since the application will maintain its state over the entire time it is running, and client context does not tie up server resources, using a DataSet can be very convenient for Windows Forms applications.

Finally as a one word I WOULD SUGGEST..


SMALLER PROJECTS REQUIRES BETTER PERFORMANCE USE DATAREADER, LARGE SCALE/BIGGER APPLICATIONS REQUIRES BETTER PERFORMANCE USE DATASET.


Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 3/23/2012 [Member] Bronze | Points: 25

Up
0
Down
Well said @Jmckamal .......
good explanation !


I think Rajendra you got your answer, if you haven't then don't hesitate to ask more !


Thanks and Regards
Akiii

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/23/2012 [Member] Silver | Points: 25

Up
0
Down
Yes ,Rightly said by JmcKamal.
For database or retrieved data is very large , but we have to show record by record then DataReader is good.
Suppose retrieved data is 400 -600 records and then you need to browse them , better to go for dataset.
Dataset is popular for its disconnected architecture.
DataReader is poupular for its faster data retrival.

Thanks,JmcKamal for your nice explanation

Thanks,
Sanjay

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Jmckamal

Nice Explanation Thanks
For n-tier Architecture which is better.
I think Data set is Better.

Thanks

Regards


R D Patel

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Purushoth on: 3/24/2012 [Member] Starter | Points: 25

Up
0
Down
If you are performing just read operation on data and you need a better performance then Data reader is good. if you also want to perform some operations on data then data set is good as you can also perform disconnected operations on records in data set which cannot be done in data reader.

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/26/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Jmckamal

Thank you for your nice and detailed answer

R D Patel

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/26/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Jmckamal,
I appreciate your effort,Thanks.

Thanks,
Sanjay

Patel28rajendra, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response