AnsweredAssumed Answered

Search Query Always Returns Nothing

Question asked by tjfan001 on Sep 22, 2016
Latest reply on Oct 28, 2016 by blake.terhune

I'm trying to search fields from the map (uri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2"). The web page reveals that it contains many fields such as the following:

Fields:

  • OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
  • Shape ( type: esriFieldTypeGeometry , alias: Shape )
  • NAME ( type: esriFieldTypeString , alias: NAME , length: 32 )
  • STATE_NAME ( type: esriFieldTypeString , alias: STATE_NAME , length: 25 )
  • STATE_FIPS ( type: esriFieldTypeString , alias: STATE_FIPS , length: 2 )
  • CNTY_FIPS ( type: esriFieldTypeString , alias: CNTY_FIPS , length: 3 )
  • FIPS ( type: esriFieldTypeString , alias: FIPS , length: 5 )
  • POP2000 ( type: esriFieldTypeInteger , alias: POP2000 )
  • POP2007 ( type: esriFieldTypeInteger , alias: POP2007 )
  • POP00_SQMI ( type: esriFieldTypeDouble , alias: POP00_SQMI )
  • POP07_SQMI ( type: esriFieldTypeDouble , alias: POP07_SQMI )

However, when I try to use the following code to perform the search, I always get nothing (findResults.Results always null). Can someone please help me to identify where it went wrong? Many thanks (mapUri is the map Uri above).

 

private async Task MyQuery()

{

   try

   {

      resultsGrid.Visibility = Visibility.Collapsed;

      resultsGrid.ItemsSource = null;

      FindTask findTask = new FindTask(mapUri);

      var param = new FindParameters()

      {

         LayerIDs = new List<int> { 0, 1, 2 },

         SearchFields = new List<string> { "STATE_NAME" },

         ReturnGeometry = true,

         SpatialReference = MyMapView.SpatialReference,

         SearchText = "Colorado"

      };

var findResults = await findTask.ExecuteAsync(param);

if ((findResults != null) && (findResults.Results != null) && (findResults.Results.Count > 0))

{

resultsGrid.ItemsSource = findResults.Results;

resultsGrid.Visibility = Visibility.Visible;

}

else

MessageBox.Show("Found Nothing!");

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "Find Sample");

}

}

Outcomes