Answered by:
How to add a row from one dataset to another dataset if previous row is a new row in master DB

Question
-
Hi guys
I actually have two DB's - Master and localExpress - I connect to each of these DB's via a Adapter/dataset confuguration. Therefore I have a _dataSetMaster and a _dataSetLocalExpress that is filled on the application load.
Please note each of my DB's has a GUID's as primary keys , I dont use any INT64 primary keys and /or autoincrement keys for either DB's.
So my question is as follows: When I Sync my app I have code that checks the _dataSetMaster rows and _dataSetLocalExpress and it will for example fin that the Admin guys (eg) has added a row to the Master DB therefore if refresh my _dataSetMaster adapter I will get an extra row in that _dataSetMaster dataset. But my _dataSetLocalExpress DOES not have this extra row and I would like a way to append / add this row to my _dataSetLocalExpress using the ADO NET functionality.
Some of you guys probably picked up that for the Syncing im using the Mircosoft Sync Framework - the syncing is working fine however I need a solution on an ADO NET level how to add my row from MAster DB to my local SQL instance. The MSoft Syncing has not panned out that well. SOme code:
_dataSetLocalExpress: (fill the dataset):
DataSetLocalExpressAdapter.CustomerAdpater localAdapter = new DataSetLocalExpressAdapter.CustomerAdpater ();
localAdapter.Fill(_dataSetLocalExpress.Customer);_dataSetMaster: (fill the dataset):
DataSetMasterAdapter.CustomerAdpater masterAdapter = new DataSetMasterAdapter.CustomerAdpater ();
masterAdapter.Fill(_dataSetMaster.Customer);
DataRow drExpress = null;foreach (DataRow dataRowExpress in (_dataSetLocalExpress.Tables[0].Rows)
{drExpress = _dataSetMaster.Customer.Rows.Find(dataRowExpress["GuidID"]);
if (drExpress != null)
{//Dont add rows from master DB as there is no new GUID
}
else
{
//else do add something cuz there a new GUID found in master DB and it needs be added to the local express DB
}
SIncere aplogies if this is a noob question and or a complete wrong way of going about it, but I need some help here as I am not getting any closer to an elgant way of resolving this.
Kind regards
Geo
Monday, November 21, 2011 2:02 PM
Answers
-
Geo,
Not sure if this could potentially help, and I certainly don't want to send you down the wrong path, but how about issuing a .Merge on the DataTables in the DataSets? You'd probably want to check to see if there are any changes in _dataSetMaster, and if so, merge the appropriate DT's in dataSetLocalExpress, then issue an update on the DataSetLocalExpressAdapter.
James Crandall ~ http://javitechnologies.com Spatial Database Solutions- Marked as answer by Allen_MSDN Friday, November 25, 2011 1:54 AM
Monday, November 21, 2011 6:33 PM
All replies
-
Geo,
Not sure if this could potentially help, and I certainly don't want to send you down the wrong path, but how about issuing a .Merge on the DataTables in the DataSets? You'd probably want to check to see if there are any changes in _dataSetMaster, and if so, merge the appropriate DT's in dataSetLocalExpress, then issue an update on the DataSetLocalExpressAdapter.
James Crandall ~ http://javitechnologies.com Spatial Database Solutions- Marked as answer by Allen_MSDN Friday, November 25, 2011 1:54 AM
Monday, November 21, 2011 6:33 PM -
Hi James
Yes that does make sense thank you :)
Tuesday, November 22, 2011 4:45 AM -
Another suggestion, Geo, if James' Merge idea doesn't work for you (although it should): try the ImportRow() method in your existing code:
foreach (DataRow dataRowExpress in (_dataSetLocalExpress.Tables[0].Rows) { drExpress = _dataSetMaster.Customer.Rows.Find(dataRowExpress["GuidID"]); if (drExpress != null) { //Dont add rows from master DB as there is no new GUID } else { //else do add something cuz there a new GUID found in master DB and it needs be added to the local express DB _dataSetLocalExpress.Tables[0].ImportRow(drExpress); } }
~~Bonnie Berent [C# MVP]
geek-goddess-bonnie.blogspot.comTuesday, November 22, 2011 5:52 AM -
Hi there Bonnie
Ok will try this approach as well, James suggestion did work however I am having a problem with updating my rows in my SQLExpress and SQLRemote.I explain the problem in the following thread:
I hope that you can guid me in the right direction.
Kind regards
Geo
Thursday, November 24, 2011 10:03 AM