AnsweredAssumed Answered

Reading data from related tables classes  arcobjects

Question asked by sibghatullah86 on Apr 2, 2017

I am using the following code to read data from related table.The function always shows "Attributed Relationship exist".

Although i have checked the relationship name its shows.please guide.


while (feature != null)
{

IRelationship_Example(feature);
count++;
feature = featureCursor.NextFeature();
}

 

 

//IRelationship Example

    public void IRelationship_Example(IFeature feature)
    {
        //assumes that only one RelationshipClass exists for the Origin feature class
        IEnumRelationshipClass enumRelClass = feature.Class.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
        IRelationshipClass relClass = enumRelClass.Next();
        //if a feature with no Relationships established has been selected, exit
        if (relClass == null)
        {
            return;
        }
        ESRI.ArcGIS.esriSystem.ISet relSet = relClass.GetObjectsRelatedToObject((IObject)feature);
        relSet.Reset();
        //If an Attributed Relationship does not exist, exit
        if (relClass.IsAttributed != true)
        {
            return;
        }
        IFeature destinationFeature = (IFeature)relSet.Next();
        while (destinationFeature != null)
        {
            IRelationship relationship = relClass.GetRelationship((IObject)feature, (IObject)destinationFeature);
            IRow row = (IRow)relationship;
            object attributeValue;
            if (row.get_Value(0) == null)
            {
                attributeValue = "0";
            }
            else
            {
                attributeValue = row.get_Value(0);
            }
            Console.WriteLine("Destination OID: {0}  Origin OID:  {1}  Attribute value:  {2}", relationship.DestinationObject.get_Value(0), relationship.OriginObject.get_Value(0), attributeValue);
            destinationFeature = (IFeature)relSet.Next();
        }
    }

Outcomes