I'm new to ArcObjects and I'm finding it difficult to work with the ArcObjects 'Feature classes'. Coming to my problem, I have a Map with few layers. I have coded for the layer names to display in the first Combo-box and the Column names of the Layer selected from the first Combo-box will be displayed in the second Combo-box. The values of the Columns will be displayed in the third Combo-box(So far, So good). But now I'm working on a query that displays the values lesser than the value selected in my third Combo-box. I have been using VB.Net coding for this purpose. The query code runs something like this.

Dim hook = ComboBox1.SelectedIndex(Table number)
    Dim FClass = ComboBox1.Text(Table Name)
    Dim Field = ComboBox2.Text(Column Name of the table selected)
    Dim Value = ComboBox4.Text(values in the Column selected)
    Dim pMxDoc As IMxDocument = TryCast(m_application.Document, IMxDocument)
    Dim pMap As IMap = pMxDoc.FocusMap
    Dim pLayer As IFeatureLayer
    pLayer = pMap.Layer(hook)
    Dim pFeatureClass As IFeatureClass = pLayer.FeatureClass
    Dim pTable As ITable = pFeatureClass

    Dim FilePath As String
    FilePath = "D:\Harsha\ArcMap_CustomTools\EGISDATA\"
    Dim pWSFact As IWorkspaceFactory
    pWSFact = New ShapefileWorkspaceFactory
    Dim pFeatureWorkspace As IFeatureWorkspace
    pFeatureWorkspace = pWSFact.OpenFromFile(FilePath, hook)
    pLayer.Name = FClass
    pTable = pLayer
    Dim pQFilter As IQueryFilter
    pQFilter = New QueryFilter
    pQFilter.SubFields = Field
    pQFilter.WhereClause = "'" + Field + "' < '" + Value + "'"
    Dim pSelSet As ISelectionSet
    pSelSet = pTable.Select(pQFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, pFeatureWorkspace)
    Dim pFeatureCursor As IFeatureCursor
    pSelSet.Search(pQFilter, False, pFeatureCursor)
    Dim iRecCount As Integer
    s = vbNullString
    Dim pFeature As IFeature
    pFeature = pFeatureCursor.NextFeature
    While Not pFeature Is Nothing
        iRecCount = iRecCount + 1
        s = s & vbCrLf & pFeature.Value(Value)
        pFeature = pFeatureCursor.NextFeature
    End While

The problem is pFeature is always Nothing and it does not enter the while loop

  • 1
    try to edit the whereclause, maybe pQFilter.WhereClause = "[" + Field + "] < '" + Value + "'" Maybe you also have to delete the ' around value... – Ms. Smith Sep 12 '17 at 9:34
  • @schmiddor The same problem exist after I made the changes. pFeature value is Nothing – k r harsha Sep 12 '17 at 9:45
  • Did you verify the where clause for example in ArcMap? – Propper Sep 12 '17 at 10:04
  • OK I now took a different approach with the iFeatureSelection . Also I implemented @schmiddor 's solution and have got the results. Yes @schmiddor I verified it and you were right. I had overlooked it. your solution was a life saver. – k r harsha Sep 12 '17 at 10:45

Your Answer

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

Browse other questions tagged or ask your own question.