Keep alive tables in DataSet

E

Earl

This question isn't so much about code as it is about development process.
I'm focused on improving the performance of an app I've developed over the
last several months. One area that has troubled me is how long to maintain a
FILLed dataset across classes and even within classes.

For example, I have a rather large form class where I fill a dataset with a
couple of tables in order to generate the dataviews that in turn populate
grids, listboxes and such. Let's say I filled a dataset, creating a
dtSuppliers table. Once I'm finished there, I clear the dataset. Later, in
order to do an update or add a new record, what I'm currently doing is
REfilling - dataset (dtSuppliers), check for changes, do the update. This
does not seem efficient, but is nonetheless safe, because there are spots in
my code where I *must* clear the dataset.

So my question is, how long to maintain a dataset fill with a particular
table? What is safe, what is unsafe? There are a gazillion books out there
and tons of pieces of example code (and I think I"ve read quite a few of
both), but even the best of authors never comes out and explains how BEST to
handle the WHEN part of maintaining tables (as it relates to clearing
datasets) in a mid-to-large app. What I'm doing now works -- but I can't
imagine in any way this is the best or most efficient way.
 
W

William Ryan eMVP

Earl said:
This question isn't so much about code as it is about development process.
I'm focused on improving the performance of an app I've developed over the
last several months. One area that has troubled me is how long to maintain a
FILLed dataset across classes and even within classes.

It really depends on the app, how many users you have, how volatile the
underlying data is etc.
For example, I have a rather large form class where I fill a dataset with a
couple of tables in order to generate the dataviews that in turn populate
grids, listboxes and such. Let's say I filled a dataset, creating a
dtSuppliers table. Once I'm finished there, I clear the dataset. Later, in
order to do an update or add a new record, what I'm currently doing is
REfilling - dataset (dtSuppliers), check for changes, do the update. This
does not seem efficient, but is nonetheless safe, because there are spots in
my code where I *must* clear the dataset.

So my question is, how long to maintain a dataset fill with a particular
table?
For lookups for instance, you may never need to refill it. For
transactional data, you may need to refill (Update is probably more
appropriate though) every minute or few minutes.

What is safe, what is unsafe?
As far as the objects themselves go, there is not 'safe' or 'unsafe'
criteria per se. They can last as long as the session and even afterward if
you serialize there data. Unless you are talking about datareaders which
need to be connected to be useful.
There are a gazillion books out there
and tons of pieces of example code (and I think I"ve read quite a few of
both), but even the best of authors never comes out and explains how BEST to
handle the WHEN part of maintaining tables (as it relates to clearing
datasets) in a mid-to-large app.
They couldn't do this. There's no golden rule. Business rules, the
underlying data, number of users etc all change the equation. If you only
have one user then you never need to clear and refill. If you have 5000
then you probably need to do it all the time.

What I'm doing now works -- but I can't
imagine in any way this is the best or most efficient way.

I"d just create a property (in most cases a Static property of type dataset)
and in the accessor, check the last time the data was accessed. If it was
longer than X , then update everything. If not, use what you have. But
again, this totally depends. We have an HR app that gets updated very
infrequently. I only update things whenever a new record is submitted.
It's worked for a year and a half without a glitch. We have another app
that has around 50 users and well over 15,000 transactions in any 8 hour
period, it would be suicide to use the same approach here.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 
E

Earl

Thanks William. I'm still chewing on parts of your response, but I wanted to
point out that my use of word "safe" was not meant so technically, rather
"safe" in the sense of corrupting the data or losing the data during a
process. And yes, I was referring solely to the dataset, not the datareader.
 

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