DataSet vs. SQL

  • Thread starter Thread starter epigram
  • Start date Start date
E

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. 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.
 
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
 
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.
 
Back
Top