novice: dataset and datareader

N

nabil m

hi , i have been looking around on msdn and google but i still have a couple
of oquestions about the difference between a datareader and a dataset -
which to use when -
1) do i have to choose between one fo the 2 in my page ?
2) i am creating a " forgot my password" page- and i want to execute a query
based on the email address entered in my form - what do i with the result -
use datareader to get the password and send by email or use the dataadapter
+ dataset to get the password /
3) also i rad that the after you create a dataset then you are able to bind
page controls to the data ?thx in advance
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

Joerg Jooss

nabil said:
hi , i have been looking around on msdn and google but i still have a
couple of oquestions about the difference between a datareader and a
dataset - which to use when -
1) do i have to choose between one fo the 2 in my page ?

No, you can use both.
2) i am creating a " forgot my password" page- and i want to execute
a query based on the email address entered in my form - what do i
with the result - use datareader to get the password and send by
email or use the dataadapter + dataset to get the password /

For such straightforward queries, I'd use an IDbCommand and a DataReader.
3) also i rad that the after you create a dataset then you are able
to bind page controls to the data ?thx in advance

Yes, you can. See the numerous samples on MSDN on server controls and data
binding.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top