How to find a string in the attributes of a layer


Summary
This topic shows how to find a string value in the attributes of one or more layers in a map resource.

Finding a string in the attributes of a layer

All successful searches in a feature layer are stored in a corresponding System.Data.DataTable in the DataTable array (the "queryResultsDataTableArray" variable) returned from a call to Find().
The map resource type is non-specific; therefore, any data source that supports queries can be used (for example, ArcIMS or ArcGIS for Server).
See the following code example:
[C#]
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource = gisFunctionality.Resource;
bool supported = gisResource.SupportsFunctionality(typeof
    (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

if (supported)
{
    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality queryFunctionality = 
        (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)
        gisResource.CreateFunctionality(typeof
        (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

    string[] layerIDs = null;
    string[] layerNames = null;
    queryFunctionality.GetQueryableLayers(null, out layerIDs, out layerNames);

    System.Collections.Generic.Dictionary < object, string = ""[] > fieldsDictionary
        = new System.Collections.Generic.Dictionary < object, string = ""[] > ();

    foreach (string layerID in layerIDs)
    {
        string[] fieldsArray = queryFunctionality.GetFields(null, layerID);
        fieldsDictionary.Add(layerID, fieldsArray);
    }

    ESRI.ArcGIS.ADF.Web.FindParameters findParameters = new
        ESRI.ArcGIS.ADF.Web.FindParameters();
    findParameters.FindOption = ESRI.ArcGIS.ADF.Web.FindOption.AllLayers;
    findParameters.LayersAndFields = fieldsDictionary;
    findParameters.FindString = "Arizona";
    findParameters.MaxRecords = 10;
    findParameters.ReturnADFGeometries = true;
    findParameters.UseSqlContains = true;

    System.Data.DataTable[] queryResultsDataTableArray = queryFunctionality.Find
        (null, findParameters);
}
[VB.NET]
Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = gisFunctionality.Resource
Dim supported As Boolean = gisResource.SupportsFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality))

If supported Then
    Dim queryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = CType(gisResource.CreateFunctionality (GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)
    
    Dim layerIDs As String() = Nothing
    Dim layerNames As String() = Nothing
    queryFunctionality.GetQueryableLayers(Nothing, layerIDs, layerNames)
    
    System.Collections.Generic.Dictionary<Object, String = ""() >
    fieldsDictionary = New System.Collections.Generic.Dictionary<Object, String = ""()>()
    
    For Each layerID As String In layerIDs
        Dim fieldsArray As String() = queryFunctionality.GetFields(Nothing, layerID)
        fieldsDictionary.Add(layerID, fieldsArray)
    Next layerID
    
    Dim findParameters As ESRI.ArcGIS.ADF.Web.FindParameters = New ESRI.ArcGIS.ADF.Web.FindParameters()
    findParameters.FindOption = ESRI.ArcGIS.ADF.Web.FindOption.AllLayers
    findParameters.LayersAndFields = fieldsDictionary
    findParameters.FindString = "Arizona"
    findParameters.MaxRecords = 10
    findParameters.ReturnADFGeometries = True
    findParameters.UseSqlContains = True
    
    Dim queryResultsDataTableArray As System.Data.DataTable() = queryFunctionality.Find(Nothing, findParameters)
End If






Additional Requirements
  • This topic assumes that a MapResourceManager and Map control (named Map1) are available in the current scope, and that a layer in a map resource has at least one feature with a field that contains "Arizona" as the value.