Generic coding

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have two identical databases A & B with several tables. Each table has an
ID and a timestamp. Is it possible to write a generic procedure that will
take the table name (as it is same in both dbs) and the names of the two dbs
and update tables in db A from corresponding tables in db B depending on
which record is most recent? I am just trying to avoid writing code for each
of the tables.

Thanks

Regards
 
John,
It sounds very possible!

What I would suggest is to write the routine for Table 1, then write the
routine for Table 2. Look for the similarities, if they are eluding you,
write the routine for Table 3, again look for similarities.

I would expect (at least hope) as soon as you start writing the routine for
Table 3 that the "pattern" hits you. Hopefully you see the pattern before
table N of N! ;-)

Part of the "trick" is going to be creating the "updates" for db A from db
B. A DataTable may be "easiest", however with or without a DataTable you're
going to need the SQL statements. Which means you will either need to
dynamically create these yourself (remembering to include all the fields) or
consider having a "generic class" where the "procedure" is in the base
class, and it calls overridable methods in the derived classes,
alternatively you could make it "table" driven, for example if table 1 uses
sp1, and table 2 uses sp2... And are all the rows matching or can there be
rows from db B that need to be inserted into db A?

If you don't have it David Sceppa's book "Microsoft ADO.NET - Core
Reference" from MS Press has some thoughts & insites on using DataTable to
"copy" data from db A to db B, you would still need the logic to verify the
timestamps...

BTW: If this is SQL Server based, wouldn't replication handle this for you?

Hope this helps
Jay
 
Back
Top