Use query result for another query.

463
2
04-21-2011 12:10 PM
JayKappy
Frequent Contributor
I am running a spatial query that is finding a polygon and retuning a field value...I can get that to a message box fine...as well as displaying the graphic for the polygon that works
What am trying to do is then use that value to fuel another query to find the point location relevant to that polygons value

I find the precinct polygon and return its precinct number (11)
In the next set of data (points) there is a field Precinct_Nu that also has a value of (11)
I am trying to uset eh varaible in the query to run the second query...

This is what I am trying but there is an issue with the query as if fails....any thoughts?  Simply tryign to get a graphic to show up.....

Thoughts?  THanks



    Private Sub QueryTask_ExecuteCompletedSpatial_Precincts(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer_Precincts.ItemsSource = args.FeatureSet.Features

        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MySelectionGraphicsLayerPrecincts"), GraphicsLayer)

        Dim PrecinctValue As String = Nothing

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            For Each feature As Graphic In featureSet.Features
                feature.Symbol = TryCast(LayoutRoot.Resources("PrecinctsFill"), FillSymbol)
                graphicsLayer.Graphics.Insert(0, feature)

                PrecinctValue = feature.Attributes("PRECINCTS_")

            Next feature
        End If

        Dim PrecinctValue2 As String = PrecinctValue
        MessageBox.Show(PrecinctValue2)

        Dim queryTask As New QueryTask("http://gis.logis.org/arcgis/rest/services/MG_Test/MapServer/18")
        AddHandler queryTask.ExecuteCompleted, AddressOf QueryTaskFindPrecinctPoints
        AddHandler queryTask.Failed, AddressOf QueryTaskFindPID_FailedPrecinctPoints

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        query.OutFields.Add("*")
        query.Where = String.Format("PrecinctNu '%{0}%'", PrecinctValue2.Trim())
        query.ReturnGeometry = True
        query.OutSpatialReference = MyMap.SpatialReference
        queryTask.ExecuteAsync(query)

' snip


    Private Sub QueryTaskFindPrecinctPoints(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet

        ' If an item has been selected            
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MySelectionGraphicsLayerPrecinctsPts"), GraphicsLayer)
        graphicsLayer.ClearGraphics()

        'If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
        If featureSet IsNot Nothing AndAlso featureSet.Features.Count < 2 Then

            ' Show selected feature attributes in DataGrid
            Dim selectedFeature As Graphic = featureSet.Features(0)

            ' Hightlight selected feature
            selectedFeature.Symbol = TryCast(LayoutRoot.Resources("StrobeMarkerSymbol_Red"), ESRI.ArcGIS.Client.Symbols.Symbol)
            graphicsLayer.Graphics.Add(selectedFeature)

            MessageBox.Show("Got One")
        ElseIf featureSet.Features.Count > 1 Then

            MessageBox.Show("No results, Please enter teh entire PID value ex. 1211922220012")
        Else
        End If
    End Sub
0 Kudos
2 Replies
JayKappy
Frequent Contributor
THINK I GOT IT.....ONE SECOND
0 Kudos
JayKappy
Frequent Contributor
Figured out one field was Double one was string.....feel stupid....thanks
0 Kudos