Nabil,
A DataReader is a class that provides forward only access to your data.
This means that if you perform a query, then you access the rows in the
query one by one, and you can not update it.
A DataAdatper takes four queries (select, insert, update, delete) and
will populate a data set based on the select query. Once you make changes
to the data set, you can pass the data set back to the data adapter, and
based on the state of the rows (changed, deleted, inserted), it will perform
the appropriate queries.
A DataAdapter actually uses a DataReader under the covers to populate
the data set.
Now when choosing between the two, you have to consider a few things.
It appears you are in an ASP.NET page, so you can actually bind controls to
either a DataReader or a DataSet. If the list that you are binding to is
not volatile (the data is pretty much the same every time you populate the
list), then I would use a data set to bind to the list. The reason for this
is that you will take the hit once for populating the data set, but on
subsequent data binds, you can retrieve the data set from the Session, or
the Cache. Subsequent binds would be much, much faster.
Also, if you want to update the data back on the database (it changes
somehow), then I would recommend a data set.
Typically, for data binding situations, I say go with the data set
(especially in windows forms applications). In ASP.NET, I would be a little
more leinient, and say that if your data is volatile (changing all the
time), then use the data reader and bind to the list to that.
In situations where you just want to process the results (like for a
report), I would say go with a data reader.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com