Sunday, March 13, 2011

Difference between Data Reader and Dataset

Hi friends, In this article I would like share some important differences between Data Reader and Dataset





Data set:

--> Dataset is a class, which is the part of System. Data Namespace
--> Dataset supports connectionless architecture. That is, active connection is not required while working with datasets
--> Dataset cannot communicate directly with database


Hence data adapter is required to carry the data in between dataset and database


--> Data Adapter is used to carry the data but not to hold the data


--> Dataset holds a collection of tables, where CLR gives an index number for every table


--> Dataset supports to create Relations with the help of primary and foreign keys


--> Dataset works with the help of xml technology


Data Reader:


--> Data Reader holds a collection of records


--> Data reader is an abstract class


--> Data Reader is forward only


--> Data Reader Is Read-only


-->Data Readers are connection oriented that is, if connection sate is opened then only data reader works


-->If connection is closed the all associated data readers will be closed automatically


-->While using data readers, if numbers of clients are more in the network then project efficiency will be decreases


Major Differences


--> “Dataset” is a disconnected architecture, while Data Reader has live connection while reading data, if we want to cache data and pass to a different tier “Dataset forms the best and it has decent Xml support.


--> When application needs to access data from more than one table “Dataset” is the best one


--> If we need to move back while reading records,” Data Reader” does not support functionality


--> The main draw back with dataset is speed. as dataset carry considerable overhead because of relations ,multiple tables etc speed is slower than “Data reader”. Always try to use “Data Reader” wherever possible, as it is meant especially for speed performance.


Syntax for Data Reader:

Sqlconnection con= new sqlconnection();


Con.open();


Sqlcommand com =new sqlcommand (select * from emptable);


Data Reader dr= com.ExecuteReader ( );      





Syntax for Dataset:


Sqlconnection con= new sqlconnection();


Con.open();


SqlDataAdapter da =new SqlDataAdapter (select * from emptable);


Dataset ds=new dataset ( );

Da.fill(ds,”newtablename”) // where newtablename is table alias name in dataset

That's it friends..
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , ,

2 Comments:

At March 13, 2011 at 6:33 PM , Blogger Dotnet Tutorials said...

Good One...

 
At August 20, 2011 at 3:41 PM , Anonymous Anonymous said...

Thanks for sharing.......

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home