ariharan3

IFeatureLayer.IFeatureClass returns nul value.

Discussion created by ariharan3 on Jan 17, 2012
Latest reply on Jan 18, 2012 by ariharan3
Hi all,

Am supposed to read the field values of feature Datas from the Map Layers, and need to store it in SQL DB.  Am getting null value in FeatureClass object of IFeatureLayer. Can anyone help to solve this issue.... Few Months back i worked with the same code, which was worked properly to read data from layers.

The code is,

  private object GetDataFromESRI(string LayerName, string FieldName, int RecordCount)
        {

            for (int LayerCount = 0; LayerCount < axMapControl1.LayerCount; LayerCount++)
            {
              
                if (axMapControl1.get_Layer(LayerCount).Name.ToString().ToUpper() == LayerName.ToString().ToUpper() && axMapControl1.get_Layer(LayerCount) is IFeatureLayer)
                {

                    //Get IFeatureLayer interface
                    IFeatureLayer featureLayer = (IFeatureLayer)axMapControl1.get_Layer(LayerCount);
                    IQueryFilter qry = new QueryFilterClass();
                 
                
                      int FieldIndex =featureLayer.FeatureClass.FindField(FieldName);  //Got Error as "NullReferenceException" Object Reference not set to an instance of an object.
                                                         
                       IFeature ESRIFeature = featureLayer.FeatureClass.GetFeature(RecordCount); //RecordCount
                       object value = ESRIFeature.get_Value(FieldIndex);
                       return value;
                  
                }
            }
            return null;
        }

Outcomes