APerlov

How to add feature with related features

Discussion created by APerlov on Jul 16, 2013
The problem is solved. It's all because of GUID format http://forums.arcgis.com/threads/36519-assigning-guid-value-to-guid-field-in-.net-c

Hello, everyone.
I need to programmatically add object with geometry to table. type of geometry may be different, so main data is stored in the table and geometry is stored in related feature class, related on Guid field.

To add data i use code like this:

 
  IFeatureLayer lyr = MapHelper.FindLayer(Properties.Settings.Default.LineStatementsLayer) as IFeatureLayer;
                if (lyr != null)
                {
                    geomfeature = lyr.FeatureClass.CreateFeature();
                    geomfeature.Shape = wrapper.Geometry;
                    int ind = geomfeature.Fields.FindField("GUID");
                    if (ind > 0)
                    {
                        MessageBox.Show(geomfeature.Value[ind].ToString());

                        geomfeature.Value[ind] = guid;

                    }

                }
               

           

            ITable table = MapHelper.FindTable(Properties.Settings.Default.StatementsTable);
            if (table != null)
            {
                feature = table.CreateRow();
                int ind = feature.Fields.FindField("LIFE_STATE");
                if (ind > 0)
                {
                    feature.Value[ind] =1;
                }
                ind = feature.Fields.FindField("GUID");
                if (ind > 0)
                {
                    feature.Value[ind]=guid;
                }
   }


when executing this code? i always get exception "The workspace is not connected" on line
"geomfeature.Value[ind] = guid;"

if i change order of adding row and geometry exception is beeing throwed on line

"feature.Value[ind]=guid;"

However setting of ShapeField and Life_State field doesn't throw any exception/ I think the cause of this problem is corrupting of referential integrity in SDE with relationclasses. Can you recommend  me a proper way to solve this problem?

Outcomes