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.
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
1 Answer 1
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.
-
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– Cody2012年03月22日 13:57:43 +00:00Commented Mar 22, 2012 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– Chaz2012年03月22日 18:53:31 +00:00Commented Mar 22, 2012 at 18:53
-
BTW - you can cast to IQueryFilterDefinition to add an "ORDER BY" clause to the .PostFixClause property.Chaz– Chaz2012年03月22日 19:03:55 +00:00Commented Mar 22, 2012 at 19:03