ESRI.ArcGIS.ADF.IMS
StoredQuery Class
Members  Example  See Also 
ESRI.ArcGIS.ADF.IMS.Carto.Layer Namespace : StoredQuery Class




Provides information about a predefined query on a layer.

Object Model


Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class StoredQuery 
Visual Basic (Usage)Copy Code
Dim instance As StoredQuery
C# 
[SerializableAttribute()]
public class StoredQuery 

Example

The following example uses a stored query in a layer to perform a query on a map layer. The stored query is retrieved from the layer's stored query collection based on the name. Then the where expression and variable name are retrieved. The value entered by the user replaces the variable name in the where expression. This where expression is then used in a Query method on the layer, and results are displayed by binding the FeatureTable to a GridView control.

In an application, error checking should be performed, and the user's input should be checked for malicious content.

C#Copy Code
FeatureLayer theLayer = (FeatureLayer)mapView.Layers.FindByName("Cities"); 

StoredQueryCollection storedQueryColl = theLayer.StoredQueries; 

         

// Find the StoredQuery with Population in the name 

StoredQuery popQuery = null; 

foreach (StoredQuery sq in storedQueryColl) 



    if (sq.Name.IndexOf("Population") > -1) 

        popQuery = sq; 



  

if (popQuery != null) 



    string sqWhere = popQuery.WhereExpression; 

    string sqVar = popQuery.Variable.Name; 

  

    // Replace the variable with the value entered by the user 

    string whereExp = sqWhere.Replace(sqVar, TextBox1.Text); 

  

    // Use the where expression in a query on the layer 

    Filter queryFilter = new Filter(whereExp); 

    QueryParameters queryParam = new QueryParameters(queryFilter); 

  

    FeatureTable queryResults = theLayer.Query(queryParam); 

  

    // Display any results in a GridView control 

    if (queryResults.Rows.Count > 0) 

    { 

        GridView1.DataSource = queryResults; 

        GridView1.DataBind(); 

    } 



    
Visual BasicCopy Code
Dim theLayer As FeatureLayer = _

    CType(mapView.Layers.FindByName("Cities"), FeatureLayer)

Dim storedQueryColl As StoredQueryCollection = _

    theLayer.StoredQueries



' Find the StoredQuery with "Population" in the name

Dim popQuery As StoredQuery = Nothing

For Each sq As StoredQuery In storedQueryColl



    If sq.Name.IndexOf("Population") > -1 Then

        popQuery = sq



    End If

Next



If Not IsNothing(popQuery) Then



    Dim sqWhere As String = popQuery.WhereExpression

    Dim sqVar As String = popQuery.Variable.Name



    ' Replace the variable with the value entered by the user

    Dim whereExp As String = sqWhere.Replace(sqVar, TextBox1.Text)



    ' Use the where expression in a query on the layer

    Dim queryFilter As New Filter(whereExp)

    Dim queryParam As New QueryParameters(queryFilter)



    Dim queryResults As FeatureTable = theLayer.Query(queryParam)



    ' Display any results in a GridView control

    If queryResults.Rows.Count > 0 Then



        GridView1.DataSource = queryResults

        GridView1.DataBind()

    End If

End If

Remarks

Stored queries are queries defined by the creator of the map service and attached to the properties of the layer. They can be used to query the layer easily, since they define all but the value needed for the query.

Stored queries define only attribute queries. Spatial queries based on geometry are not supported.

Stored queries are supported with standard ArcIMS image services. They are not available with ArcMap Server image services. See the ArcIMS Help, in the ArcXML Guide, for more information on setting up stored queries.

Stored queries cannot be used directly to query the layer. Instead, you can use the properties of the stored query to set up the QueryParameters, which can then be used to query the layer. For example, the WhereExpression of the StoredQuery can be used in the WhereExpression of the Filter object in the QueryParameters.

In order to use the WhereExpression, you will need to substitute the value you want to query for the query variable in the where expression. For instance, the WhereExpression in the StoredQuery could be:

POPULATION > [var>]

In this case, the "[var]" will need to be replaced with a search value, such as 1000. The string of the variable to be replaced is given in Variable.

Only a single variable is supported for replacement purposes.

Inheritance Hierarchy

System.Object
   ESRI.ArcGIS.ADF.IMS.Carto.Layer.StoredQuery

See Also

© 2010 All Rights Reserved.