469,272 Members | 1,439 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,272 developers. It's quick & easy.

DataSet vs. SQL

I'd like to know when a DataSet is the preferred way to retrieve, and
specifically update/delete, data in an ASP.NET application. I've been using
straight SQL by using the SqlCommand and SqlDataReader objects. I'd like to
know if there is anything wrong with this approach. It appears that if you
want to use a DataSet for an update that you have to persist it so you can
use it in a subsequent postback. That seems like it might become expensive,
but maybe the cost of persisting it is outweighed by some other optimization
that I am not aware of. Any help would be much appreciated.

Thanks.
Nov 19 '05 #1
2 1163
SqlDataReader will be slightly faster than the DataSet when just using them
for data binding, primarily because the DataSet is an extra in-memory copy
of the data. So if your situation is just data binding, then go for the data
reader approach. But this also means you're always going to the data base
for the data. If you're looking to hold onto the data for a longer period
(for caching purposes or for doing extra processing on the data) then that's
when you'd prefer a DataSet. The DataSet also allows you to create additional
columns that are calculated and in conjunction with the DataView you can
easily get sorting and filtering (not that you can't with SQL statements
back in the DB, but the work's offloaded to the webserver).

Anyway, the fact that you're simply aware of the two is a good start. Each
one has its place.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'd like to know when a DataSet is the preferred way to retrieve, and
specifically update/delete, data in an ASP.NET application. I've been
using straight SQL by using the SqlCommand and SqlDataReader objects.
I'd like to know if there is anything wrong with this approach. It
appears that if you want to use a DataSet for an update that you have
to persist it so you can use it in a subsequent postback. That seems
like it might become expensive, but maybe the cost of persisting it is
outweighed by some other optimization that I am not aware of. Any
help would be much appreciated.

Thanks.


Nov 19 '05 #2
Hi epigram,
I'd like to know when a DataSet is the preferred way to retrieve, and
specifically update/delete, data in an ASP.NET application.
The first scenario that comes to mind is when you SELECT a group of records,
allow the client to edit multiple records, and then do an UPDATE of all the
edited records in one swell foop.

You are wise to want to eliminate unnecessary overhead in your app. If
you're updating a single Record, the method you've described is going to be
faster and more efficient. Just be aware that the more responsibility you
take for yourself by going to a lower level (a DataSet is populated by a
DataReader internally), you will have to accept that responsiblity and
handle it well, such as making sure that the DataReader and Connection are
closed in your code.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"epigram" <no****@spammy.com> wrote in message
news:1114513511.e4292df6a5fd5c9974b04a38277393cd@b ubbanews... I'd like to know when a DataSet is the preferred way to retrieve, and
specifically update/delete, data in an ASP.NET application. I've been
using straight SQL by using the SqlCommand and SqlDataReader objects. I'd
like to know if there is anything wrong with this approach. It appears
that if you want to use a DataSet for an update that you have to persist
it so you can use it in a subsequent postback. That seems like it might
become expensive, but maybe the cost of persisting it is outweighed by
some other optimization that I am not aware of. Any help would be much
appreciated.

Thanks.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mike | last post: by
2 posts views Thread by John Holmes | last post: by
22 posts views Thread by Arne | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.