Refreshing data in dataset

  • Thread starter Thread starter No One
  • Start date Start date
N

No One

Hi,
I'm after some advice on the best way to refresh a dataset with any changes
made to the database by other users. I've been calling the DataAdapter.Fill
method and this works very well to update data in the dataset but the one
limitation is that is doesn't remove records deleted from the database. I
could call the Dataset.Clear method but this causes the GUI components to
reset back to the first record in the tables.

Thanks for your help.
 
Hi,

DataAdapter.Fill is the best possible way to refresh a dataset.
If you want to refresh a table with the current values from the
server while retaining any changes made to the rows in the table,
you must first populate it with DataAdapter.Fill, fill a new DataTable,
and then Merge that DataTable into the DataSet with a preserveChanges value
of true.

HTH

Mona
 
Thanks for your help. The Merge method does work very well but the only
thing it doesn't seem to do is remove records from the Table that have been
deleted from the Sql Server database by other users.
 
Yup and for delete, you need to refresh your dataset.

Think of it this way "merge" merges .. it doesn't know anything about what
got deleted from the db. Most good apps actually don't delete anyway, they
just mark a flag "Deleted" - so it is retreivable afterwards. Not to mention
too many deletes and your table keeps growing (unless you truncate it,
refill it .. etc. etc.) .. long story.

In short, yes merge won't help you resolve deletes and that is by design.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Back
Top