Home All Groups Group Topic Archive Search About

Comparing Two DataTables

Author
24 May 2006 1:17 AM
c_shah
Scenario: I have to update my SQL server table from an ORACLE database
to keep my SQL table in sync with ORACLE.

I have one data table that is populated form ORACLE and other one is
populating from SQL server (Both data tables are part of the same
dataset). How to programmatically compare two tables and update the SQL
server data table?

Thanks in advance.

Author
24 May 2006 3:00 AM
Steven Nagy
Other than data, will the comparison need to include schema differences
between the two tables? If so, does it need to update the columns as
necessary in the SQL table?

If its only data, then you can use the datatable's find method to pull
back each row. Then iterate through the columns collection against both
rows and check the individual values.

Ie.

Dim dtOracle as datatable = dataset.Tables("OracleTable")
Dim dtSQL as datatable = dataset.Tables("SQLTable")
for each oracleRow as DataRow in dtOracle.Rows
    Dim sqlRows() as datarow =
dtSQL.Find(CINT(oracleRow("primarykeycolumnname")))
    if sqlRows.length > 0 then
    for each field as datacolumn in dtOracle.Columns
        if sqlRows(0)(field.Name) <> oracleRow(field.Name) then
             sqlRows(0)(field.Name) = oracleRow(field.Name)
        end if
    next
    end if
next



Something like that. My code is probably wrong, so look at it as pseudo
code!
Author
24 May 2006 8:16 AM
Cor Ligthert [MVP]
Hi,

This completely depend on how independen the data is from the time, is that
not than you need beside a kind of code as Stevens pseudo code a timestamp
in all datarows that you want to merge.

I hope this helps,

Cor

Show quoteHide quote
"c_shah" <shah.chi***@netzero.net> schreef in bericht
news:1148433437.717744.213600@j55g2000cwa.googlegroups.com...
> Scenario: I have to update my SQL server table from an ORACLE database
> to keep my SQL table in sync with ORACLE.
>
> I have one data table that is populated form ORACLE and other one is
> populating from SQL server (Both data tables are part of the same
> dataset). How to programmatically compare two tables and update the SQL
> server data table?
>
> Thanks in advance.
>