ArcObjects Library Reference (GeoDatabase)  

IQueryName.QueryDef Property

QueryDef of feature class name.

[Visual Basic .NET]
Public Property QueryDef As IQueryDef
[C#]
public IQueryDef QueryDef {get; set;}
[C++]
HRESULT get_QueryDef(
  IQueryDef** QueryDef
);
[C++]
HRESULT put_QueryDef(
  IQueryDef* QueryDef
);
[C++]

Parameters

QueryDef [out, retval]

  QueryDef is a parameter of type IQueryDef

QueryDef [in]

  QueryDef is a parameter of type IQueryDef

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

    public void IQueryName__(IWorkspace workspace)
    {
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
        IQueryDef queryDef = featureWorkspace.CreateQueryDef();
        //examples of query def construction

        //Valid sub fields
        queryDef.SubFields = "Parcel.Area, Parcel.Parcel_ID";
        //Invalid sub fields
        //queryDef.SubFields = "max(Parcel.Area) as Max_Area";

        //Valid tables
        queryDef.Tables = "Parcels, Owners"; 
        //Invalid tables
        //queryDef.Tables = "Parcels p, Owners o";
        //queryDef.Tables = "Owners INNER JOIN parcels ON Owners.Parcel_id = parcels.Parcel_id";

        //Valid where clause
        queryDef.WhereClause = "Owner.Name like '%Smith%' and Owner.Address like '%Main Street%'";
        //Invalid where clause
        //queryDef.WhereClause = "Owner.Name like '%Smith%' group by Owner.City_Address";

        //set QueryDef property
        IQueryName queryName = new TableQueryNameClass();
        queryName.QueryDef = queryDef;
    }

Remarks

The IQueryDef::Subfields, IQueryDef::Tables and IQueryDef::WhereClause properties of the QueryDef are used to generate a SQL statement. This is executed against the database to return the rows represented by the table or feature class opened from the name object. If the QueryDef properties are not set properly, you may get errors or incorrect results. The following describes how to define these properties properly:

IQueryDef::Subfields - This must be a comma delimited list of field names or a * to indicate all columns. Column aliases and functions are invalid.

IQueryDef::Tables - This needs to be a comma delimited list of tables. Join statements or table aliases are invalid.

IQueryDef::WhereClause - Most WhereClauses are valid, but additonal statements like Order by and Group by are not.

See the IQueryDef interface for more information on QueryDefs.

See Also

IQueryName Interface

.NET Related Topics

Joining data | Querying geodatabase tables |