Select to view content in your preferred language

Attribute Query Sample Issue - Help Needed

2250
2
Jump to solution
09-13-2012 08:48 AM
BrianLord1
Deactivated User
Hello,

I am trying to use the Attribute Query Sample from the sdk, but am having issues getting it to work.  I am new to silverlight (and programming altogether) so any help would be greatly appreciated.

I can get the dropdown list to populate with the correct data, but when I select an item nothing else happens.  Through the use of message boxes I know that the correct item is passed through the query statements within the QueryComboBox_SelectionChangedselectionchanged event, but that the QueryTask_ExecuteCompleted event does not receive anything into its "args" parameter.

Here is the code...

Private Sub QueryComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)         If QueryComboBox.SelectedItem.ToString().Contains("Select...") Then             Return         End If          Dim queryTask As New QueryTask("http://xxxxxxxx/ArcGIS/rest/services/xxxxxx/MapServer/1")         AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted         AddHandler queryTask.Failed, AddressOf QueryTask_Failed           Dim query As New ESRI.ArcGIS.Client.Tasks.Query()         query.Text = QueryComboBox.SelectedItem.ToString()         query.ReturnGeometry = True         query.OutSpatialReference = MainMap.SpatialReference         query.OutFields.Add("*") 


At this point, query.Text still has the correct value for the selected item.

        queryTask.ExecuteAsync(query)     End Sub      Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)         Dim featureSet As FeatureSet = args.FeatureSet 


At this point the featureset.Count says it is 0.

        ' If initial query to populate states combo box         If (TryCast(args.UserState, String)) = "initial" Then             ' Just show on initial load             QueryComboBox.Items.Add("Select...")              For Each graphic As Graphic In args.FeatureSet.Features                 QueryComboBox.Items.Add(graphic.Attributes("PRECINCT").ToString())             Next graphic              QueryComboBox.SelectedIndex = 0             Return         End If          ' Remove the first entry if "Select..."         If QueryComboBox.Items(0).ToString().Contains("Select...") Then             QueryComboBox.Items.RemoveAt(0)         End If          ' If an item has been selected                     Dim graphicsLayer As GraphicsLayer = TryCast(MainMap.Layers("MyGraphicsLayer1"), GraphicsLayer)         graphicsLayer.ClearGraphics()          If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then             ' Show selected feature attributes in DataGrid             Dim selectedFeature As Graphic = featureSet.Features(0)             QueryDetailsDataGrid.ItemsSource = selectedFeature.Attributes              ' Highlight selected feature             selectedFeature.Symbol = TryCast(LayoutRoot.Resources("DefaultFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)             graphicsLayer.Graphics.Add(selectedFeature) ...


Thanks again.

Mark
0 Kudos
1 Solution

Accepted Solutions
BrianLord1
Deactivated User
I found the issue.  The query.Text statement was not working properly for some reason (not exactly sure why).  I found that the query.Where statement could be substituted.  After some time of playing around with the SQL syntax i got everything to work.

Here is the code works...
        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()         query.ReturnGeometry = True         query.OutSpatialReference = MainMap.SpatialReference         query.OutFields.Add("*")         query.Where = String.Format("PRECINCT LIKE '%{0}%'", QueryComboBox.SelectedItem.ToString)          queryTask.ExecuteAsync(query)

View solution in original post

0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
No idea.

I suggest you use fiddler to look at the query request sent to the server.
That might give a clue.
0 Kudos
BrianLord1
Deactivated User
I found the issue.  The query.Text statement was not working properly for some reason (not exactly sure why).  I found that the query.Where statement could be substituted.  After some time of playing around with the SQL syntax i got everything to work.

Here is the code works...
        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()         query.ReturnGeometry = True         query.OutSpatialReference = MainMap.SpatialReference         query.OutFields.Add("*")         query.Where = String.Format("PRECINCT LIKE '%{0}%'", QueryComboBox.SelectedItem.ToString)          queryTask.ExecuteAsync(query)
0 Kudos