HOWTO: Reload DataSet?

M

mitmed

Hello,

I'm working on basic VB.NET winforms Client-Server application with
SQLServer as backend.
When users open a particular form, the data is loaded into DataSet and
controls are bounded to it. When one user changes the data and saves
it, the changes are saved to the database and also reflected on his
dataset. However, the changes are not seen by other users, who have
the same form open, until they reload their datasets.

Is this a normal .NET behavior?
Is there a way to automatically propagate the changes?
If not, how can I efficiently reload the DataSet? (Our datasets are
quite big, around 20,000 records)
When reloading a DataSet, do I have to rebind the controls too?

Thanks in advance.

Regards,
Dmitri
 
S

Sanjeeva

Yeah, The best you can do is you can have some time period,
after which you get the data back from server and rebind the controls.
It depends on what kind of data you are showing to the user which most
likely can be opened by
two guys simultaneously. Do this only for the data which has this
poosibility, since it is an expensive affair.

Regards
Sanjeeva
Proteans Software Solutions
 
D

David Hanson

The DataSet is a disconnected object and will not be automatically
synchronized with the data on the actual database server after it has been
originalled filled with information.

If you truly need to maintain an up-to-date copy of the information on the
client at all times you will have to write custom code to handle that
requirement. Here are a few thoughts on how you might approach this (please
note: I have never done this myself, I'm just thinking outloud in the hope
it will benefit you):

- create a new table in your database called "TableLastModified" and
add a column called "TableName" and a column called "LastModifiedOn". The
"TableName" field should be char/varchar and should contain the name of the
table you want to track. The "LastModifiedOn" column should be DateTime and
should store the date/time you last modified data for the table in question.
You will need to modify any code the information in the tables to update
this new "TableLastModified" table after each change.

- Populate your dataset on the client and record the date/time you
populated it in a variable

- Place a timer on your Window's client form and have it fire an event
every XX seconds. Have the code in the event check the appropriate record
in the "TableLastModified" table to see when the information for the table
was last modified. If the value is more recent then the value you have
stored in your variable then reload the dataset and update the value of your
variable.

You could also look at using a timestamp column instead of a DateTime column
for the "TableLastModified" table. I suspect there would be some advantages
of using the timestamp instead because it would be more accurate. The
DateTime column falls short because if two clients update the database at
the EXACT SAME TIME and you read the dataset after the 1st update you will
miss the second client's updates. May never happen, but it's possible. The
timestamp approach gaurantees you a unique number.

Just my $0.02. :)

Hope that helps.

ps: Does anyone else have a different approach?

Best Regards,

David
 

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