ArcObjects Library Reference  (GeoDatabase)    

RelQryTabExample_csharp

[Visual Basic 6.0]

The following vb6 code example uses a RelQueryTable to join a Table to a FeatureClass . It then prints the names of the fields in the RelQueryTable.

Private Sub RelQryTabExample(pFCls As IFeatureClass, strFClsFld As String, pTable As ITable, strTabFld As String)

  ' ++ Create the MemoryRelationshipClass that defines what is to be joined
  Dim pMemRelClassFact As IMemoryRelationshipClassFactory
  Set pMemRelClassFact = New MemoryRelationshipClassFactory
  Dim pRelClass As IRelationshipClass
  Set pRelClass = pMemRelClassFact.Open("Country_Demog", pFCls, _
  strFClsFld, pTable, strTabFld, "forward", "backward", esriRelCardinalityOneToMany)

  ' ++ Perform the join   
  Dim pRelQueryTableFact As IRelQueryTableFactory
  Dim pRelQueryTab As ITable
  Set pRelQueryTableFact = New RelQueryTableFactory
  Set pRelQueryTab = pRelQueryTableFact.Open(pRelClass, True, Nothing, Nothing, "", True, True)

  ' ++ Print the fields  
  Dim pCursor As ICursor
  Set pCursor = pRelQueryTab.Search(Nothing, True)
  
  Dim pField As IField
  Dim pFields As IFields
  Dim intI As Integer, intJ As Integer
  
  Set pFields = pCursor.Fields
  intI = pFields.FieldCount - 1
  For intJ = 0 To intI
    Set pField = pFields.Field(intJ)
    Debug.Print pField.Name
  Next intJ
End Sub

[C#]

The following C# code example uses a RelQueryTable to join a Table to a FeatureClass . It then prints the names of the fields in the RelQueryTable.

public void RelQryTabExample(IFeatureClass featureClass, string featureClassField, ITable table, string tableField)
{
  // Create the MemoryRelationshipClass that defines what is to be joined
  IMemoryRelationshipClassFactory memoryRelationshipClassFactory = new MemoryRelationshipClassFactoryClass();
  IRelationshipClass relationshipClass = memoryRelationshipClassFactory.Open("samplejoin", (IObjectClass)featureClass, featureClassField, (IObjectClass)table, tableField, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
 
  // Perform the join   
  IRelQueryTableFactory relQueryTableFactory = new RelQueryTableFactoryClass();
  ITable relQueryTable = (ITable)relQueryTableFactory.Open(relationshipClass, true, null, null, "", true, true);
 
  // Print the fields  
  ICursor cursor = relQueryTable.Search(null, true);
  IFields fields = cursor.Fields;
  int i = fields.FieldCount; 
  for(int j = 0; j < i; j++){
    IField field = fields.get_Field(j);
    Console.WriteLine(field.Name);
  }
}

[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.