I have :

  • FeatureClass (Structure)
  • column (Type)
  • column (OID)

I am trying to get the (Type) for specific OID. I tried to use this code but it dose not work.

IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureClass testFeatureClass = featureWorkspace.OpenFeatureClass("Structure");
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.SubFields = "Type";
queryFilter.WhereClause = "OBJECTID = " + feature.OID;
IFeatureCursor fCursor = testFeatureClass.Search(queryFilter, true);

I don't know what is the wrong, any help would be appreciated.

  • 1
    Can you elaborate on "does not work"? Exception? Zero features in the cursor? Feature has no data value for the field? – Jay Cummins Jun 19 '12 at 10:02

You can get field value by doing the following. 1. Select your feature. 2. Cursor through feature to see if selection set is > 1 (below is code example for step 2).

IFeatureSelection pFSel = default(IFeatureSelection);
pFSel = pFLayer;
ESRI.ArcGIS.Geodatabase.ISelectionSet2 pSelSet = default(ESRI.ArcGIS.Geodatabase.ISelectionSet2);
pSelSet = pFSel.SelectionSet;
if (pSelSet.Count < 1) {
    MsgBox("No Features Selected")

ESRI.ArcGIS.Geodatabase.IFeatureCursor pFCursor = null;
pSelSet.Search(null, false, pFCursor);

IFeature pFeature = default(IFeature);
pFeature = pFCursor.NextFeature;
// Get First Feature
if (pFeature == null) {
    Interaction.MsgBox("No Features Selected!");
    // Just in case, but probably already taken care of earlier

long lFIndex = 0;
lFIndex = pFCursor.FindField(m_strGridIndexField);
// Replace with your field name
if (lFIndex > -1) {
    // Substute the correct data type to match the field type
    while ((pFeature != null)) {
        m_fValue = pFeature.Value(lFIndex);
        // Do something with the value stored in fValue
        pFeature = pFCursor.NextFeature;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.