My task is to fill a DataSet from a data source and update another data source in C#.
For example I have two databases in SQL Server (i.e. db1 and db2).
I have table named ProdMkt_Contrib_Link in db1 with following columns:
ProdMkt_Contrib_Link
--------------------
ProdMktContributorID (PK)
ProductMarketID
Priority
Inactive
Contrib_Type_Override
ProdMkt_Contrib_Link_ID
The above columns data should be mapped/sync to the table named ProdMktContribLink in db2:
ProdMktContribLink
------------------
ProdMktContributorID (PK)
ProductMarketID
Priority
InactiveFG
ContribTypeOverRide
AcumenProdMktContribLinkID
Note: The table name and few column name are different.
Suppose few records are added and few are updated in the b1.ProdMkt_Contrib_Link table.
I have filled the typed DataSet (DS1) with db1.ProdMkt_Contrib_Link (this contains only added and updated records) ans also filled the another DataSet (DS2) with db2.ProdMktContribLink (this contains all records).
Now I want that DS1 should be sync with the DS2. That is, the added records should be added to the DS2 table rows and also updated records should be updated to the DS2 table rows.
What is the best way to accomplish this in c#. Please suggest any good design or sample code.
Thanks,
Kamran
anup dawarePosted Feb 8, 2007, 10:51 AM
I am a little doubtful about use of triggers!
How can updates on one database cause the triggers of other database to get fired?
Best Regards,
Anup Daware
Crito PhilippatosPosted Feb 8, 2007, 10:35 AM
anup dawarePosted Feb 8, 2007, 3:09 AM
if you have both databases active at a time, better do the updates in one transaction or procedure.
Description:
lests say you have your Database1.TestTable and Database2.TestTable.
Now if any query is updating the Database1.TestTable a similar query should be fired to update the Database2.TestTable and this should happen in ONE transaction(Read about transactions if you are not aware of this) thus with the concept of automicity this will always ensure that either both databases are updated or none :)
Let us know if this helped you or you found some other solution :)
Best Regards,
Anup