Reading Related tables class arcobjects

2032
0
04-02-2017 09:48 PM
SibghatUllah1
Occasional Contributor
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();
        }
    }
0 Kudos
0 Replies