[Visual Basic 6.0]Public Sub JoinTable() ' The following code performs a one-to-one, left-outer join on the first layer ' in the map and the first table in the map using a memory relationship ' class. The join field is “STFIPS” in the layer and "STATE_FIPS" in the table. ' In IMemoryRelationshipClassFactory::Open, it is important to specify the ' layer’s feature class as the pOriginForeignClass rather than the ' pOriginPrimaryClass. Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pLayer As IGeoFeatureLayer Dim pDpyRC As IDisplayRelationshipClass Dim pTableColl As ITableCollection Dim pTable As ITable Dim pMemRCFact As IMemoryRelationshipClassFactory Dim pRelClass As IRelationshipClass Set pMxDoc = Application.Document Set pMap = pMxDoc.FocusMap ' get a reference to the layer Set pLayer = pMap.Layer(0) Set pDpyRC = pLayer ' get a reference to the table Set pTableColl = pMap Set pTable = pTableColl.Table(0) ' create a relationship class in memory Set pMemRCFact = New MemoryRelationshipClassFactory Set pRelClass = pMemRCFact.Open("Demo", pTable, "STATE_FIPS", pLayer.FeatureClass, _ "STFIPS", "Forwards", "Backwards", esriRelCardinalityOneToOne) ' perform the join pDpyRC.DisplayRelationshipClass pRelClass, esriLeftOuterJoin End SubPublic Sub JoinWithGDBRelate()
' the following code performs a layer join using a predefined relationship in a
' geodatabase. if the layer's feature class participates in more than one
' relationship class, then the join will be created based on the first
' relationship class found in the collection.
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As IGeoFeatureLayer
Dim pDpyRC As IDisplayRelationshipClass
Dim pFeatClass As IFeatureClass
Dim pEnumRC As IEnumRelationshipClass
Dim pRelClass As IRelationshipClass
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
' get a reference to the layer
Set pLayer = pMap.Layer(0)
Set pDpyRC = pLayer
' get the relationship class from the layer's feature class
Set pFeatClass = pLayer.FeatureClass
Set pEnumRC = pFeatClass.RelationshipClasses(esriRelRoleDestination)
' get the first relationship class in the collection
Set pRelClass = pEnumRC.Next
' perform the join
pDpyRC.DisplayRelationshipClass pRelClass, esriLeftOuterJoin
End Sub
[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button
in the upper-left corner of the page.