Join multiple tables

Discussion created by Grieck on Oct 18, 2011
Hello Forum,

How do you join multiple tables?

I have successfully created a join between a table and a feature class and displayed the results in the table. I was also able to manipulate the displayed results by picking the fields in both tables that I wanted to display and highlighting and setting some fields to read only.

I'd like to do the same thing but add three more tables. There is existing relationship class between the tables.

I tried this, but I don't think it's working.

        ITable f = GetTable(f);
        Type mrcfType = Type.GetTypeFromProgID("esriGeodatabase.MemoryRelationshipClassFactory");
        IMemoryRelationshipClassFactory mrcf = (IMemoryRelationshipClassFactory)Activator.CreateInstance(mrcfType);
        IGeoFeatureLayer tgfl = (IGeoFeatureLayer)GetCurrentLayer("t", 0);
        IRelationshipClass rc = mrcf.Open("MyReport", p as IObjectClass, "fid", tgfl.DisplayFeatureClass, "fid", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
        IDisplayRelationshipClass pDisplayRelClass = (IDisplayRelationshipClass)tgfl;
        pDisplayRelClass.DisplayRelationshipClass(rc, esriJoinType.esriLeftOuterJoin);

        IGeoFeatureLayer agfl = (IGeoFeatureLayer)GetCurrentLayer("a", 0);
        mrcf = (IMemoryRelationshipClassFactory)Activator.CreateInstance(mrcfType);
        IRelationshipClass arc = mrcf.Open("MyReport", f as IObjectClass, "aid", agfl.DisplayFeatureClass, "aid", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
        pDisplayRelClass = (IDisplayRelationshipClass)agfl;
        pDisplayRelClass.DisplayRelationshipClass(arc, esriJoinType.esriLeftOuterJoin);

        IGeoFeatureLayer bgfl = (IGeoFeatureLayer)GetCurrentLayer("b", 0);
        mrcf = (IMemoryRelationshipClassFactory)Activator.CreateInstance(mrcfType);
        IRelationshipClass brc = mrcf.Open("MyReport", f as IObjectClass, "bid", bgfl.DisplayFeatureClass, "bid", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
        pDisplayRelClass = (IDisplayRelationshipClass)bgfl;
        pDisplayRelClass.DisplayRelationshipClass(brc, esriJoinType.esriLeftOuterJoin);

         IGeoFeatureLayer cgfl = (IGeoFeatureLayer)GetCurrentLayer("c", 0);
        mrcf = (IMemoryRelationshipClassFactory)Activator.CreateInstance(mrcfType);
        IRelationshipClass crc = mrcf.Open("MyReport", f as IObjectClass, "cid", cgfl.DisplayFeatureClass, "cid", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
        pDisplayRelClass = (IDisplayRelationshipClass)cgfl;
        pDisplayRelClass.DisplayRelationshipClass(crc, esriJoinType.esriLeftOuterJoin);
The first join is between a table (p) and a feature class (t) where t is one and p is many. The results should be stored in the table p.

The next join is between a feature class (a) and feature class (t) where a is one and t is many.
The next join is between a feature class (b) and feature class (t) where b is one and t is many.
The next join is between a feature class (c) and feature class (t) where c is one and t is many.

I need to be able to instantiate IStandaloneTable from IDisplayRelationshipClass and specifically set IStandaloneTable.Table I'm assuming this would be the table used to create the join.

Once that's working I can perform queries on the joined data and extract what I need and display it how I want using the same procedures as I've used before.

I've looked at the following old thread but I'm not certain I have things defined correctly. Apparently there were some changes that needed to be made to the function.