ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Data Namespace / Table Class / Search Method
This argument is optional. If unset or set to null, a default query filter will be used, which will cause all rows to be returned.
If set to true, all the entries in RowCursor will reference the most current row returned by Current. To ensure all the entries in RowCursor remain unique, set useRecyclingCursor to false. The default is true.
Example

In This Topic
    Search Method (Table)
    In This Topic
    Searches and retrieves specific rows in this Table that satisfy the criteria set in the queryFilter. If no query filter is set, all rows will be retrieved. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function Search( _
       Optional ByVal queryFilter As QueryFilter, _
       Optional ByVal useRecyclingCursor As Boolean _
    ) As RowCursor

    Parameters

    queryFilter
    This argument is optional. If unset or set to null, a default query filter will be used, which will cause all rows to be returned.
    useRecyclingCursor
    If set to true, all the entries in RowCursor will reference the most current row returned by Current. To ensure all the entries in RowCursor remain unique, set useRecyclingCursor to false. The default is true.

    Return Value

    A RowCursor that encapsulates the retrieved rows.
    Exceptions
    ExceptionDescription
    If queryFilter is an instance of SpatialQueryFilter, either both the 'FilterGeometry' and 'SpatialRelationship' properties are set or both are not set. Otherwise, an ArgumentException will be raised.
    A geodatabase-related exception has occurred.
    Example
    Searching a Table using QueryFilter
    public async Task SearchingATable()
    {
      try
      {
        await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
        {
          using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
          using (Table table = geodatabase.OpenDataset<Table>("EmployeeInfo"))
          {
    
            QueryFilter queryFilter = new QueryFilter
            {
              WhereClause = "COSTCTRN = 'Information Technology'",
              SubFields = "KNOWNAS, OFFICE, LOCATION",
              PostfixClause = "ORDER BY OFFICE"
            };
    
            using (RowCursor rowCursor = table.Search(queryFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  string location = Convert.ToString(row["LOCATION"]);
                  string knownAs = Convert.ToString(row["KNOWNAS"]);
                }
              }
            }
          }
        });
      }
      catch (GeodatabaseFieldException fieldException)
      {
        // One of the fields in the where clause might not exist. There are multiple ways this can be handled:
        // Handle error appropriately
      }
      catch (Exception exception)
      {
        // logger.Error(exception.Message);
      }
    }
    Searching a Table using a set of ObjectIDs
    public RowCursor SearchingATable(Table table, IReadOnlyList<long> objectIDs)
    {
      QueryFilter queryFilter = new QueryFilter()
      {
        ObjectIDs = objectIDs
      };
    
      return table.Search(queryFilter);
    }
    Searching a FeatureClass using SpatialQueryFilter
    public async Task SearchingAFeatureClass()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass schoolBoundaryFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.SchoolBoundary"))
        {
          // Using a spatial query filter to find all features which have a certain district name and lying within a given Polygon.
          SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter
          {
            WhereClause = "DISTRCTNAME = 'Indian Prairie School District 204'",
            FilterGeometry = new PolygonBuilderEx(new List<Coordinate2D>
            {
              new Coordinate2D(1021880, 1867396),
              new Coordinate2D(1028223, 1870705),
              new Coordinate2D(1031165, 1866844),
              new Coordinate2D(1025373, 1860501),
              new Coordinate2D(1021788, 1863810)
            }).ToGeometry(),
    
            SpatialRelationship = SpatialRelationship.Within
          };
    
          using (RowCursor indianPrairieCursor = schoolBoundaryFeatureClass.Search(spatialQueryFilter, false))
          {
            while (indianPrairieCursor.MoveNext())
            {
              using (Feature feature = (Feature)indianPrairieCursor.Current)
              {
                // Process the feature. For example...
                Console.WriteLine(feature.GetObjectID());
              }
            }
          }
        }
      });
    }
    Fetching a Row from an Element
    // usage :   using (var row = FetchRowFromElement(...))
    public static Row FetchRowFromElement(UtilityNetwork utilityNetwork, Element element)
    {
      // Get the table from the element
      using (Table table = utilityNetwork.GetTable(element.NetworkSource))
      {
        // Create a query filter to fetch the appropriate row
        QueryFilter queryFilter = new QueryFilter()
        {
          ObjectIDs = new List<long>() { element.ObjectID }
        };
    
        // Fetch and return the row
        using (RowCursor rowCursor = table.Search(queryFilter))
        {
          if (rowCursor.MoveNext())
          {
            return rowCursor.Current;
          }
          return null;
        }
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also