
The Query task allows you to retrieve features from a feature layer in an ArcGIS Server map service or a spatially-enabled table in SQL Server via the MapIt Spatial Data Service. Features can be retrieved using spatial and/or attribute query parameters. Once the features are returned, you can use .NET code to display their geometries and attributes in your Silverlight/WPF application. To use a Query task, you will need to include code to define its user interface and specify its execution logic.
An example of XAML and .NET code (in this case C#) for a simple Silverlight application that includes a Query task is shown below. This application defines a Query task that uses a TextBox control for specifying the query and a button for executing the task. Result features are displayed in a GraphicsLayer that has MapTips enabled. The rest of this document will walk you through how the Query task is defined in the example.
[XAML]
<UserControl x:Class="SilverlightApp.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client" xmlns:esriConverters="clr-namespace:ESRI.ArcGIS.Client.ValueConverters;assembly=ESRI.ArcGIS.Client" xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"> <Grid x:Name="LayoutRoot" Background="White"> <!-- QUERY TASK OUTPUT RESOURCES --> <Grid.Resources> <esriConverters:DictionaryConverter x:Name="MyDictionaryConverter" /> <esriSymbols:SimpleFillSymbol x:Name="ResultsFillSymbol" Fill="#500000FF" BorderBrush="Blue" BorderThickness="1" /> </Grid.Resources> <!-- MAP --> <esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" > <esri:Map.Layers> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/> <esri:GraphicsLayer ID="MyGraphicsLayer"> <esri:GraphicsLayer.MapTip> <Grid Background="LightYellow"> <StackPanel> <TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=STATE_NAME, Mode=OneWay}" FontWeight="Bold" /> <StackPanel Orientation="Horizontal"> <TextBlock Text="Population Density (2007): " /> <TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=POP07_SQMI, Mode=OneWay}" /> </StackPanel> </StackPanel> <Border BorderBrush="Black" BorderThickness="1" /> </Grid> </esri:GraphicsLayer.MapTip> </esri:GraphicsLayer> </esri:Map.Layers> </esri:Map> <!-- QUERY TASK INTERFACE --> <Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" > <Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" /> <TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" /> <TextBox x:Name="QueryTextBox" Width="150" Margin="15,22,0,0" Text="POP07_SQMI > 500" /> <Button x:Name="QueryButton" Content="Execute" Margin="168,23,0,0" Click="QueryButton_Click" /> </Canvas> </Grid> </UserControl>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Symbols;
using ESRI.ArcGIS.Client.ValueConverters;
namespace SilverlightApp
{
public partial class Page : UserControl
{
public Page() { InitializeComponent(); }
// Do query when execute button is clicked
private void QueryButton_Click(object sender, RoutedEventArgs e)
{
// Query task initialization
QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
"Demographics/ESRI_Census_USA/MapServer/5");
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
queryTask.Failed += QueryTask_Failed;
// Query task parameters. Return geometry, state, and population density.
Query query = new Query();
query.ReturnGeometry = true;
query.OutFields.AddRange(new string[] { "STATE_NAME", "POP07_SQMI" });
// Use textbox text as query condition.
query.Where = QueryTextBox.Text;
queryTask.ExecuteAsync(query);
}
// Draw results when query is complete
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
// Clear previous results
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
// Check for new results
FeatureSet featureSet = args.FeatureSet;
if (featureSet.Features.Count > 0)
{
// Add results to map
foreach (Graphic resultFeature in featureSet.Features)
{
resultFeature.Symbol = ResultsFillSymbol;
graphicsLayer.Graphics.Add(resultFeature);
}
}
else
{
MessageBox.Show("No features found");
}
}
// Notify when query fails
private void QueryTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Query failed: " + args.Error);
}
}
}
The following steps assume you have created a Silverlight application with a map and a base layer as described in Creating a Map. The XAML view of your application's main page (e.g. Page.xaml) should be similar to the following:
<UserControl x:Class="SilverlightApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client">
<Grid x:Name="LayoutRoot" Background="White">
<!-- MAP -->
<esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
</esri:Map.Layers>
</esri:Map>
</Grid>
</UserControl>
The code in the main page's code-behind (e.g. Page.xaml.cs) should be unchanged from when you created your Silverlight application project in Visual Studio.
Since tasks do not define user interfaces, you need to implement an interface for the Query task's input to allow your application's users to execute queries. For this, the example simply includes a TextBox for defining the query and a Button to execute the task.
<Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" > </Canvas>
<Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
</Canvas><Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
<TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" />
</Canvas><Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
<TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" />
<TextBox x:Name="QueryTextBox" Width="150" Margin="15,22,0,0" />
</Canvas><Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
<TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" />
<TextBox x:Name="QueryTextBox" Width="150" Margin="15,22,0,0" Text="POP07_SQMI > 500" />
</Canvas><Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
<TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" />
<TextBox x:Name="QueryTextBox" Width="150" Margin="15,22,0,0" Text="POP07_SQMI > 500" />
<Button x:Name="QueryButton" Content="Execute" Margin="168,23,0,0" />
</Canvas><Canvas HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,7,0" Width="250" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="230" Height="55" />
<TextBlock Text="Type a query and click Execute" Foreground="White" FontSize="10" Margin="10,5,0,0" />
<TextBox x:Name="QueryTextBox" Width="150" Margin="15,22,0,0" Text="POP07_SQMI > 500" />
<Button x:Name="QueryButton" Content="Execute" Margin="168,23,0,0" Click="QueryButton_Click" />
</Canvas>To display the results of the Query task, you need to specify an output interface. For displaying the geometry of results, you will define a GraphicsLayer in the Map element and a SimpleFillSymbol as a static resource. Then you will specify MapTips on the GraphicsLayer for displaying results' attributes. The MapTips will use the DictionaryConverter class to enable binding to attributes on the Query task's results.
<UserControl x:Class="SilverlightApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
xmlns:esriConverters="clr-namespace:ESRI.ArcGIS.Client.ValueConverters;assembly=ESRI.ArcGIS.Client"
xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"><Grid.Resources> <esriConverters:DictionaryConverter x:Name="MyDictionaryConverter" /> </Grid.Resources>
<Grid.Resources>
<esriConverters:DictionaryConverter x:Name="MyDictionaryConverter" />
<esriSymbols:SimpleFillSymbol x:Name="ResultsFillSymbol" Fill="#500000FF" BorderBrush="Blue"
BorderThickness="1" />
</Grid.Resources><esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map>
<esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map>
<esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
<TextBlock FontWeight="Bold" />
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map><esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter},
ConverterParameter=STATE_NAME, Mode=OneWay}" FontWeight="Bold" />
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map><esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter},
ConverterParameter=STATE_NAME, Mode=OneWay}" FontWeight="Bold" />
<StackPanel Orientation="Horizontal">
</StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map><esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter},
ConverterParameter=STATE_NAME, Mode=OneWay}" FontWeight="Bold" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Population Density (2007): " />
</StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map><esri:Map x:Name="MyMap" Extent="-80.05,36.93,-68.79,43.18" >
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel>
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter},
ConverterParameter=STATE_NAME, Mode=OneWay}" FontWeight="Bold" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Population Density (2007): " />
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter},
ConverterParameter=POP07_SQMI, Mode=OneWay}" />
</StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
</esri:Map.Layers>
</esri:Map>Now that you've specified the Query task's user interface, you need to define its execution logic. This execution logic can be divided into three parts:
You will implement these components in .NET code contained in the main page's code-behind. This code is linked to the XAML presentation layer by manipulating elements that you declared in XAML with "x:Name" or "ID" attributes and implementing methods that you declared in XAML as event handlers. The steps below assume that you are adding code to the Page class in the code-behind file for your Silverlight application's main page (e.g. Page.xaml.cs). In this example, C# is used.
Executing the task
To execute a query task, you need to instantiate the task, specify the layer that will be queried, wire the task's event handlers, initialize the task's query parameters, and call the task's execution method. The steps below will show you how to do this in the code-behind of your application's main page (e.g. Page.xaml.cs). The task is declared and initialized in the code-behind because tasks alone do not define any user interface, but rather encapsulate pieces of execution logic. In Silverlight, XAML is reserved for an application's presentation layer, while the code-behind is where business logic is implemented.
The code shown in these steps is written in C#.
- In the code-behind class of your application's main page, implement a handler for the QueryButton control's click event. Recall that you declared this handler when you defined the QueryButton control in the page's XAML.
private void QueryButton_Click(object sender, RoutedEventArgs e) { }
- In the click handler, declare and instantiate a Query task. The constructor accepts a URL to the server-side feature layer on which the query will execute. The URL can reference a feature layer in an ArcGIS Server map service or a table in a SQL Server database served by the MapIt Spatial Data Service. To find the URL, you can use the ArcGIS Services Directory or the MapIt Spatial Data Services Directory. This example uses the states layer in the ArcGIS Server ESRI_Census_USA map service.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); }
- Specify a handler for the task's ExecuteCompleted event. The method specified will be called when the Query task is done executing. You will implement the handler in the "Displaying results" section.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; }
- Specify a handler for the task's Failed event, which fires when there is a problem executing the query. You will define the handler in the "Handling execute errors" section.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; }
- Declare a Query object and instantiate it. The Query object is used to define the execution parameters for Query tasks.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new Query(); }
- Since you will draw the query results on the map, specify that the query return geometry with the results.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new Query(); query.ReturnGeometry = true; }
- Define the fields to return with the query results. Here you will specify that the query return the state name and population density fields. Note that only the fields required by your application should be returned so that network traffic is minimized.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new Query(); query.ReturnGeometry = true; query.OutFields.AddRange(new string[] { "STATE_NAME", "POP07_SQMI" }); }
- Specify the where clause for the query as the text contained in the QueryTextBox control. The where clause defines the conditions that features must satisfy to be returned in the query results.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new Query(); query.ReturnGeometry = true; query.OutFields.AddRange(new string[] { "STATE_NAME", "POP07_SQMI" }); query.Where = QueryTextBox.Text; }
- Execute the query task.
private void QueryButton_Click(object sender, RoutedEventArgs e) { QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new Query(); query.ReturnGeometry = true; query.OutFields.AddRange(new string[] { "STATE_NAME", "POP07_SQMI" }); query.Where = QueryTextBox.Text; queryTask.ExecuteAsync(query); }Displaying results
- Declare a handler for the Query task's ExecuteCompleted event. This handler will be invoked when a query is complete. A FeatureSet containing thefeatures that satisfy the query is passed to the handler's args parameter.
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { }- Get a reference to the results GraphicsLayer and clear any previously added graphics from it.
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); }- Check whether any results satisfying the query were found.
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); if (args.FeatureSet.Features.Count > 0) { } else { } }
- If results were found, loop through them. Apply the results fill symbol you declared in the page's XAML to each feature. Then add it to the results GraphicsLayer.
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); if (args.FeatureSet.Features.Count > 0) { foreach (Graphic resultFeature in args.FeatureSet.Features) { resultFeature.Symbol = ResultsFillSymbol; graphicsLayer.Graphics.Add(resultFeature); } } else { } }- If no features satsified the query, notify the user with a MessageBox.
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); if (args.FeatureSet.Features.Count > 0) { foreach (Graphic resultFeature in args.FeatureSet.Features) { resultFeature.Symbol = ResultsFillSymbol; graphicsLayer.Graphics.Add(resultFeature); } } else { MessageBox.Show("No features found"); } }Handling execution errors
- Declare a handler for the Query task's Failed event. This handler will be invoked if there is a problem with executing a query.
private void QueryTask_Failed(object sender, TaskFailedEventArgs args) { }- Notify the user of the problem with a MessageBox
private void QueryTask_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("Query failed: " + args.Error); }