Select to view content in your preferred language

vb.net compare fields in two tables

1594
2
10-29-2010 11:15 AM
KevinThomas1
Emerging Contributor
Hello all,
We have a .dbf table of employee home addresses and work locations.  Every quarter we are supposed to receive an update for this table.  What I need to do is compare changes in employee home address field and work location field between the original and the update.

Any suggestions on how to do this via ArcObjects?


thanks
0 Kudos
2 Replies
NeilClemmons
Honored Contributor
Join the two tables together and run a query to select the records where the field in the old table does not equal the field in the new table.  You should be able to do this in ArcMap without writing any code but you can do it through code if you want.
0 Kudos
RichardFairhurst
MVP Alum
Hello all,
We have a .dbf table of employee home addresses and work locations.  Every quarter we are supposed to receive an update for this table.  What I need to do is compare changes in employee home address field and work location field between the original and the update.

Any suggestions on how to do this via ArcObjects?


thanks


In ArcObjects you can operate on a layer with a join and access the joined fields or query the joined records through the IDisplayTable interface.  Some sample code (in VBA) that assumes the joined layer is the first layer in the map and already has a join in place is as follows:

Public Sub GetDifferencesInJoinedRecords()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pFLayer As IFeatureLayer
    Set pFLayer = pMxDoc.FocusMap.Layer(0) 'Get first layer
    
    Dim pDisplayTable As IDisplayTable
    Set pDisplayTable = pFLayer
    
    If Not TypeOf pDisplayTable.DisplayTable Is IRelQueryTable Then
       MsgBox "Feature Layer is not joined!  Exiting Sub."
       Exit Sub
    End If
    
    Dim pQF as IQueryFilter
    Set pQF = New QueryFilter

    ' Add some type of SQL selection to compare your joined table.  Test it first in the Select by Attributes dialog
    pQF.Whereclause = "ParentTableName.MyField <> JoinTableName.MyField"

    Dim pTableCursor As ICursor
    Set pTableCursor = pDisplayTable.SearchDisplayTable pQF, False
    Dim pRow As IRow
    Set pRow = pTableCursor.NextRow
    
     Dim pParentIndex As Long
    pParentIndex = pDisplayTable.DisplayTable.Fields.FindField("ParentTableName.myField") ' Substitute the actual Parent Table Name and Field Name
    If pParentIndex = -1 Then
      MsgBox "ParentTableName.myField Field Not Found! Exiting Sub." ' Substitute the appropriate message.
      Exit Sub
    End If
    
    Dim pJoinIndex As Long
    pJoinIndex = pDisplayTable.DisplayTable.Fields.FindField("JoinTableName.myField") ' Substitute the real Join Table Name and Field Name
    If pJoinIndex = -1 Then
      MsgBox "JoinTableName.myField Field Not Found! Exiting Sub." ' Fix the Message for your data
      Exit Sub
    End If
    
    Do Until pRow Is Nothing ' Keep your loop as tight as possible and do not do Dim statements inside of it.
        ' Do something in the loop
        Debug.Print pRow.Value(pParentIndex) & " <> " & pRow.Value(pJoinIndex) ' report value of field in join table
        Set pRow = pTableCursor.NextRow
    Loop
Exit Sub