Update one table from another with DataAdapter

G

Guest

I've got a scenario that I can't seem to figure out how to handle
appropriately. First of all, I've got two tables in a database that both
contain roughly 90% of the same data...meaning, most fields in each table are
the same, with the exception of a few fields in each table. One contains
baseline data, and the other contains override data (the baseline data never
changes, and any modifications the users wish to make to the baseline data
should get saved as an "override" to the other table). For my purposes here,
I'll refer to them as TableA (baseline data) and TableB (override data).

I've got a Windows Form application that is being built on top of this data
which displays this combined data in a screen. By this I mean that the screen
shows baseline data (from TableA) in fields that have not been overridden,
and override data (from TableB) when an override of a field exists.

As far as DataBinding fields on my form, I think the easiest thing to do is
to just bind everything to TableA. But, before performing DataBinding, after
loading up my DataSet, I loop through each of the records in TableA and check
to see if there's a corresponding record in TableB. If there is, then I loop
through all of the fields in that record in TableA, and compare the value in
the field to the corresponding field in the record in TableB, and if their
values are different, I update that field in the record in TableA with the
value from the record in TableB. This gives me a single DataTable that I can
bind to with both baseline and override data. That seems to be working fine
so far.

My problem is that I can't seem to figure out how to perform an update on
this data. There are a couple of things that need to be considered in order
to do this right. First, when I perform a commit of the data in my DataSet, I
need to actually update TableB in the database from TableA in my DataSet. I
can't seem to figure out how to appropriately identify that TableA in the
DataSet should update TableB in the Database. Second, if a user makes
modifications to a baseline record from TableA that doesn't already have an
existing/corresponding override record in TableB, I need to figure out how to
tell it to insert a new record into TableB with just the overridden values
from TableA.

If someone could point me in the right direction for how to do this, it
would help me out tremendously. Thanks much.

--
/*
|| YEX
|| <)))><
|| http://yexley.net/bob/
*/
 
W

W.G. Ryan - MVP

Are you using the 2.0 Framework? If so, you can set the
AcceptChangesDuringUpdate to false on your adapter and you can use the same
table twice and call update with two different adapters. Also, I'm probalby
having a little trouble getting my arms around the scenario, but I think you
can take the two datasets, if I understand you correctly and call .Merge on
the datasets - then you can call update on this (taking into account the
acceptchangesduringupdate if necessary) and go from there.

HTH,

Bill
 

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