Select to view content in your preferred language

IFeatureLayer.IFeatureClass returns nul value.

633
4
01-17-2012 03:33 AM
Ariharan
Deactivated User
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;
        }
0 Kudos
4 Replies
AlexanderGray
Honored Contributor
Sounds to me like the data is no longer where it was originally when this last worked.  Whenever I have a layer with a broken data source, the layer's featureclass is null.  Is it all the layers?  If you skip layers with null featureclasses, can you get valid ones?  Idatalayer2.Datasourcename contains an IName.  You can cast that to an IDatasetName which has a name property which is the name of the featureclass stored.  The workspacename will give you access to the properties of the workspace so you can check which database you are connecting to and under which credentials.  Once you get all that, check to see if that exists (ArcCatalog comes in handy here if you have access to it.)
Good luck!
0 Kudos
Ariharan
Deactivated User
Thanks Alex,

Can i read all the Rows of FeatureClass using the IDataSetName? I am suppossed to read the records from the layers. Can you please suggest some possible ways to do it... Can i have code sample, how to use IDatasetName

Actually the data source is not broken. I can view the layers and the Attribute Table in ARcMAp Application with this new path of MapDocument(mxd).
0 Kudos
AlexanderGray
Honored Contributor
You can't read the rows of an idatasetname.  The datasetname contains metadata about the featureclass, such as where it is and what type of featureclass it is, it is not the featureclass itself.  The point I am trying to make is if your datalayers are broken, as in the data source has been moved or removed, you will neither be able to access the featureclass nor the rows.  You can't read what isn't there.  But if you can read where the layer is expecting to have data, you can look to see if the data is indeed missing or not.  If it is missing, well then you know that is the problem.  You will have to put the data back in the expected location or point the layers to a new location where the data is.  Its' like your trying to open a file and read the lines from a directory but the file is not there, you will never be able to read the lines if you don't have the file.
0 Kudos
Ariharan
Deactivated User
Thanks again Alex,

Now i found the reason for issue. Actualy, the files were in the same location.


But am using Visual Studio 2010 version to work with ArcGIS 10.0....

Previously i worked in Visual Studio 2008 Version along with ArcGIS 10.0, which was worked successfully.


But, the think is, in 2008 and 2010 both the version of visual studio i have mentioned the Application Target Framework  as ".NET Framework 3.5".
In such case, where is the issue? I need to change any other Build Setting?



Or we need to run anyother Batch setup to support with Visual Studio 4.0(2010) Framework
0 Kudos