Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

Thank you,

Try
    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

        cbattribute.Items.Clear()

        selitem.Select(cblayernameselect)

        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
            cbattribute.Items.Add(row)
        Next row

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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