Subscribe Now!

Enter your email address:

Thursday, January 27, 2011

DataSet Vs Datareader


DataReader:
Datareader fetch data one by one from the database. You can have one row(record)  at a time in datareader. Once you read next row with read method of the datareader the older record is destroyed from memory and new record will take place instead of it. You can do that only forward only and you can not modify the data. It also require a database connection to stayed open while fetching data. You can useCommandBehavior.CloseConnection property to close connection after data reader finish reading data from database.
Dataset:
You can call dataset a mini database in your memory. Dataset support disconnected architecture as once you fill dataset with data then no connection is required. A database can contain multiple tables also its supports relationship between them. You can insert,update and delete records from dataset and you can update them also in database.
Where i should use dataset over database?
When you are required to display only data then use datareader.Dataset will fetch data once a time. So if you are having millions of records then it will consume your server memory while datareader will have just one record at a time in database. And you need not to display millions of records at time.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...