The GIS Professional Group

IDisplayRelationshipClassを使用したテーブル結合情報の取得

Public Sub GetTableJoinData()
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDocument.FocusMap.Layer(0)
    
    Dim pDisplayRelationshipClass  As IDisplayRelationshipClass
    Set pDisplayRelationshipClass = pFeatureLayer
    
    Dim pRelationshipClass As IRelationshipClass
    Set pRelationshipClass = pDisplayRelationshipClass.RelationshipClass
    
    
    Dim pDestinationClass As IObjectClass
    Set pDestinationClass = pRelationshipClass.OriginClass
    
    Debug.Print "結合元テーブル名:", pDestinationClass.AliasName
    Debug.Print "結合元フィールド名:", pRelationshipClass.OriginForeignKey
        
    Dim pOriginClass As IObjectClass
    Set pOriginClass = pRelationshipClass.OriginClass
    
    Debug.Print "結合先テーブル名:", pOriginClass.AliasName
    Debug.Print "結合先フィールド名:", pRelationshipClass.OriginPrimaryKey
    
    Dim pDataset As IDataset
    Set pDataset = pOriginClass
    
    Debug.Print "結合先データベースのパス名", pDataset.Workspace.PathName
    
    'DBMS のデータベース名
    If TypeOf pDataset.Workspace Is IDatabaseConnectionInfo Then
        Dim pDatabaseConnectionInfo As IDatabaseConnectionInfo4
        Set pDatabaseConnectionInfo = pDataset.Workspace
        
        Debug.Print pDatabaseConnectionInfo.ConnectedDatabase
    End If
   
End Sub

  • B!