to use or not to use a dataset

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi all,
I am writing a web form to edit SQL Server data. When the form loads, I am
going to read a single record from a SQL Server table and display it's
column values in textboxes,dropdowns,etc. The table contains about 60 to 70
fields(columns) and I need to display all of them on the form. So my
question is should I read the values in a DataSet? And what is the best way
to save data back to SQL Server?
Thanks.
-Nikhil
 
Hi,

I would use DataSet.
It has a bit of overhead compared to DataReader approach, however, creating
save mechanism is easier IMO - there are also wizards that help you.
You would need a DataAdapter to store data back to database.
 
Xavier Pacheco said:
While it's true that the code is easier to work with, I almost always
lean to the better performing alternative even if it requires more work.

In my experience, that's usually a mistake. The time to make that
decision is after benchmarking the particular application and finding
out whether that overhead is relevant - I suspect that it very, very
rarely is. "Premature optimisation is the root of all evil" and all
that.

I wouldn't actually use a full DataSet though - I'd just use DataTable.
That makes things even simpler.
 
Jon Skeet said:
In my experience, that's usually a mistake. The time to make that
decision is after benchmarking the particular application and finding
out whether that overhead is relevant - I suspect that it very, very
rarely is. "Premature optimisation is the root of all evil" and all
that.

Yes, true.
I wouldn't actually use a full DataSet though - I'd just use DataTable.
That makes things even simpler.

However, in this case you would loose strong typing (or you might turn to
CodeSmith to do it for you (strong typing) - better, smarter and easier than
wizards).
www.ericjsmith.net/codesmith
 
However, in this case you would loose strong typing (or you might turn to
CodeSmith to do it for you (strong typing) - better, smarter and easier than
wizards).
www.ericjsmith.net/codesmith

Yes, that's true. I'm so used to working on the Compact Framework where
there *aren't* strongly typed datasets, I don't tend to think of them
:(
 
Miha,

I miss something, what is a strongly typed datareader?

And

How are you so sure that an application with 70 different fields using a
datareader will win from basicly nothing else than when used a dataset (in a
kind of VBNet pseudo).

Select * from mytable
bla bla
da.fill(mydataset)

for each ctr as control in myform.controls
if typeof ctr is textbox then
directcast(ctr,textbox).databindings.Add(New Binding("Text",
mydataset.Tables(0), ctr.tag.tostring))
end if
next

(While you even can take a part of the name of the textbox when you make
them equal using substring or just place the textboxes dynamicly on form and
give them a numer from two digits at the end and use those)

I get as well the idea that you say using datatables makes things simpler,
you can in my opinion not use 10% from the functionality from dotDet when
you use only a datatable instead of a dataset. By instance XML in a
webservice, dsWriteXML and even more important datarelations and a lot more,
how do you come on that opinion, I would never have expected that from you,
probably I did understand this wrong?

(For me a datatable is an equivalent to a disconnected recordset, which has
even less functionality from that)

You know written with a friendly smile on my face.

Cor
 
Cor Ligthert said:
I miss something, what is a strongly typed datareader?

There's no such thing, as far as I know, and Miha wasn't suggesting
there was.

Reread the thread - Miha was suggesting using a DataSet (presumably a
strongly typed one). Xavier was suggesting using a DataReader instead.

I get as well the idea that you say using datatables makes things simpler

Again, Miha didn't suggest that - I did.
you can in my opinion not use 10% from the functionality from dotDet when
you use only a datatable instead of a dataset. By instance XML in a
webservice, dsWriteXML and even more important datarelations and a lot more,
how do you come on that opinion, I would never have expected that from you,
probably I did understand this wrong?

Your 10% figure seems pretty arbitrary - and in this case, there's
absolutely no indication that relations or XML are required. The OP
wants to read a single row from a table, display it to the user, and
then write it back to the database. No need for inter-table relations,
no need for web services.

When there are reasons to use a DataSet, use it - but if you only need
the functionality required by DataTable, why add the extra layer?
 
I do understand what you're saying. My own experience with these
ASP.NET apps is that most of the time, the data is being read in a
read-only fashion or as a single-record case as in Nikhil's situation.
I have done performance testing on the differences and depending on how
the site is going to be used, a datareader may be the better option.
Nevertheless, your point is taken.

--
Xavier Pacheco
Xapware Technologies Inc

manage your projects: www.xapware.com/ActiveFocus.htm
the blog: www.xavierpacheco.com/xlog
the book: www.amazon.com/exec/obidos/ASIN/0672324431//xavierpacheco-20
 
Back
Top