Difference between datareader and dataset?
Answer Posted / sudheendra
DataReader
Datareader is like a forward only recordset. It fetches one
row at a time so very less Network Cost compare to
DataSet(Fetches all the rows at a time). DataReader is
readonly so we cannot do any transaction on them. DataReader
will be the best choice where we need to show the data to
the user which requires no transaction ie reports. Due to
DataReader is forward only we cannot fetch the data
randomly. .NET Dataproviders optimizes the datareaders to
handle the huge amount of data.
DataSet
DataSet is always a bulky object that requires lot of memory
space compare to DataReader. We can say the dataset as a
small database coz it stores the schema and data in the
application memory area. DataSet fetches all data from the
datasource at a time to its memory area. So we can traverse
through the object to get required data like qureying database.
The dataset maintains the relationships among the datatables
inside
it. We can manipulate the realational data as XML using
dataset.We can do transactions (insert/update/delete) on
them and finally the modifications can be updated to the
actual database. This provides impressive flexibility to the
application but with the cost of memory space. DataSet
maintains the original data and the modified data seperately
which requires more memory space. If the amount of data in
the dataset is huge
then it will reduce the applications performance dramatically.
The following points will improve the performane of a dataset...
1. Don't use the commandbuilder to generate the sql statements.
Though it reduces the development time the query generated
by the command builder will not be always as required. For
example
To update the details of an author table the command
| Is This Answer Correct ? | 3 Yes | 3 No |
Post New Answer View All Answers
How to create data relations?
How to perform sorting on a table in ADO.NET?
What are the advantages of using datalist?
What is a serialized object?
What are the different methods available under the sqlcommand class to access the data?
Explain the two fundamental objects in ado.net?
How to check if a datareader is closed or opened? IsClosed()
What are the Features and disadvantages of dataset
What is connection string?
How many major types of connection objects in ADO.NET?
How do you merge 2 datasets into the third dataset in a simple manner?
What is defaultview in datatable?
Which object holds only data and does not interact with data source?
What are the namespaces used in ADO.Net to connect to a database?
What is the executescalar method?