DataSet Merge on a 3 tier model

  • Thread starter Thread starter nevin
  • Start date Start date
N

nevin

Hi All,

I have a DataTier in a remoting object which at the moment caches a simple
db.
Clients request filtered data which is returned to them in a new dataset
which they display in a grid...all ok.
If I update one field of one row (never a primary key field) I do something
like:

BindingManagerBase bmb = this.BindingContext[grdMessages.DataSource,
grdMessages.DataMember];
DataRowView drv = bmb.Current as DataRowView;
// update the row
drv.Row["req_grp_ID"] = gid;

DataSet dsnew = ((DataSet)grdMessages.DataSource).GetChanges();

// send the updated row to the remoting server
ClientRequest.UpdateRequest(dsnew);


The server takes the dataset and merges it:

MainDataset.Merge(dsnew, true);
MainDataset.AcceptChanges();

The Client then makes a call to the remoting server to return again the
filtered data I want to view. Nothing changes in the client, and I still get
the old data back from the filtered dataset from the server.

I would have thought that as I'm not updating the database directly I would
be able to just merge the clients data into the servers cached dataset
AcceptChanges would then have the new data confirmed into the cached
dataset. Any subsequent filter commands on the cached dataset would include
the new client updates.
Why wouldn't it ?
 
Hi nevin,


MainDataset.Merge(dsnew, true);
MainDataset.AcceptChanges();

The Client then makes a call to the remoting server to return again the
filtered data I want to view. Nothing changes in the client, and I still get
the old data back from the filtered dataset from the server.

I would have thought that as I'm not updating the database directly I would
be able to just merge the clients data into the servers cached dataset
AcceptChanges would then have the new data confirmed into the cached
dataset. Any subsequent filter commands on the cached dataset would include
the new client updates.
Why wouldn't it ?

You should use MainDataset.Merge(dsnew, *false*); or just
MainDataset.Merge(dsnew).
True means that the MainDataset will preserve the values.
 
Ah thanks Miha.

One other question though. As the server is just caching the data, how do I
get it to actually update the DB periodically? As the cache could now have
quite a few updated and inserted rows with various fields updated etc. Do I
have to provide a StoredProcedure for update that takes every single field
as a parameter, move through the dataset one row at a time (based on
RowState) and fill the parameters or is this implicitly done for me ?

Thanks
 
Hi,

Actually it is easier than that.
You have to create an adapter per table.
And invoke them:
adapter.Update(dataset.table);
Adapter will use (sql) commands defined for insert/update/delete that can be
either sql stataments or storedprocedures.
Since it is a quite large topic (very flexible - many options), you might
check
Dataset Updates in Visual Studio .NET
vs.net help topic.

HTH,
 
Thanks again Miha.

Miha Markic said:
Hi,

Actually it is easier than that.
You have to create an adapter per table.
And invoke them:
adapter.Update(dataset.table);
Adapter will use (sql) commands defined for insert/update/delete that can be
either sql stataments or storedprocedures.
Since it is a quite large topic (very flexible - many options), you might
check
Dataset Updates in Visual Studio .NET
vs.net help topic.

HTH,
--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

do Do
 
Back
Top