Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Question: When to use DataReader, DataAdapter

i just wondering, what things i have to consider when using DataReader and DataAdapter in fetching data from the database and whats the difference between this two other the datareader needs open connection and the datadapter does not... In our projects, were using DataReader in ALL our DAL, we never use dataadapter. So I wondering what scenario would it been better to use DataAdapter + Datatable combo than using DataReader. Thanks in advance.

like image 468
CSharpNoob Avatar asked Sep 12 '10 04:09

CSharpNoob


1 Answers

DataReader : This is best used when you just want to fetch data in readony mode , populate your business entity and close the reader. This is really fast.

Say suppose , you are having a customer class and you want to have fully initilized object with all your customer properties filled like( Name,Address etc..)

You will use DataReader here and just populate the entity and close reader.

You cannot do update with datareader.

DataAdapter : You can Read/Update the data with dataadapters but it is less faster when reading the data then Datareader.

You can update the data with DataAdapter but with reader you won't

like image 198
TalentTuner Avatar answered Oct 14 '22 18:10

TalentTuner