I am using the ArcGIS Explorer SDK and have run into an issue surrounding a query I would like to perform with SQL. I believe my query is built wrong or perhaps I am looking at the wrong fields. Would anyone have any input on my code below and/or possible solutions?

I would like the code to query a column for specific values then return them into a combo box. My query simply returns a blank value at the moment. Below is the code for that block.

    Dim md As MapDisplay = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay
        Dim map As Map = md.Map
        Dim cblayernameselect As MapItem = cblayername.SelectedItem
        Dim cbfieldnameselect As String = cbfieldname.SelectedItem
        Dim selitem As SelectedItemsCollection = ESRI.ArcGISExplorer.Application.Application.SelectedItems



        Dim child As PackageChildLayer = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems(0), PackageChildLayer)
        Dim layertable As Table = child.Table

        Dim cbcolumn As Column = layertable.Columns.Item(cbfieldnameselect)

        Dim whereclause As String = "SELECT " & cbcolumn.Name & " FROM " & layertable.Name

        Dim rows As RowCollection = layertable.Search(New Filter(whereclause))

        For Each row In rows
        Next row

    Catch ex As Exception
    End Try

Without reading all of your question I will guess the answer! You are sending a complete T-SQL 'SELECT' statement when the QueryFilter WhereClause property is just that - a where clause (what comes after the 'WHERE' keyword.) Create a QueryFilter with a valid WhereClause and populate the SubFields property with the fields you want returned.

| improve this answer | |
  • Would you have any idea how this would work for a Distinct selection? For example I would like to SELECT DISTINCT columnname FROM table I unfortunatly haven't been able to fit this into the whereclause. My returned query is always blank unfortunatly. – Cody Mar 22 '12 at 13:57
  • .SubFields can be prefaced with a "DISTINCT" clause. .WhereClause is what comes after "WHERE." .SubFields is what goes between "SELECT" and "WHERE." – Chaz Mar 22 '12 at 18:53
  • BTW - you can cast to IQueryFilterDefinition to add an "ORDER BY" clause to the .PostFixClause property. – Chaz Mar 22 '12 at 19:03

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.