This document is archived and information here might be outdated.  Recommended version.


Perform Attribute Query Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Perform Attribute Query Snippet

Creates an attribute query based on a supplied table and where clause.

[C#]
///<summary>Creates an attribute query based on a supplied table and where clause.</summary>
///  
///<param name="table">An ESRI.ArcGIS.Geodatabase.ITable, this could be a table or feature class</param>
///<param name="whereClause">A System.String, (e.g., "city_name='Redlands'").</param>
///   
///<returns>An ICursor holding the results of the query will be returned.</returns>
///   
///<remarks>The SQL syntax used to specify the where clause is the same as that of the underlying database holding the data. If you would like to return everything in the table supply "" for the where clause.</remarks>
public ESRI.ArcGIS.Geodatabase.ICursor PerformAttributeQuery(ESRI.ArcGIS.Geodatabase.ITable table, System.String whereClause)
{
  ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter=new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
  queryFilter.WhereClause=whereClause; // create the where clause statement
    
  // query the table passed into the function and use a cursor to hold the results
  ESRI.ArcGIS.Geodatabase.ICursor cursor=table.Search(queryFilter, false);

  return cursor;
}
[Visual Basic .NET]
'''<summary>Creates an attribute query based on a supplied table and where clause.</summary>
'''  
'''<param name="table">An ESRI.ArcGIS.Geodatabase.ITable, this could be a table or feature class</param>
'''<param name="whereClause">A System.String, (e.g., "city_name='Redlands'").</param>
'''   
'''<returns>An ICursor holding the results of the query will be returned.</returns>
'''   
'''<remarks>The SQL syntax used to specify the where clause is the same as that of the underlying database holding the data. If you would like to return everything in the table supply "" for the where clause.</remarks>
Public Function PerformAttributeQuery(ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal whereClause As System.String) As ESRI.ArcGIS.Geodatabase.ICursor

  Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter=New ESRI.ArcGIS.Geodatabase.QueryFilterClass()
  queryFilter.WhereClause=whereClause ' create the where clause statement

  ' query the table passed into the function and use a cursor to hold the results
  Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor=table.Search(queryFilter, False)

  Return cursor

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.System