ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / BasicFeatureLayer Class / IsValidDefinitionQuery Method / IsValidDefinitionQuery(String) Method
The SQL clause to check.
Example

In This Topic
    IsValidDefinitionQuery(String) Method
    In This Topic
    Determines if the specified SQL where clause has valid syntax. That is; the field defined exists on the layer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public Task<bool> IsValidDefinitionQuery( 
       string sql
    )
    Public Overloads Function IsValidDefinitionQuery( _
       ByVal sql As String _
    ) As Task(Of Boolean)

    Parameters

    sql
    The SQL clause to check.

    Return Value

    True if valid.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    This method does not check whether records will be returned from the SQL query; just whether the query has valid syntax for the layer.
    Example
    Apply a Definition Query Filter to a Feature Layer
    {
      var us_parks = map.GetLayersAsFlattenedList()
                        .OfType<FeatureLayer>().First(l => l.Name == "USNationalParks");
    
      var sql = "STATE_ABBR = 'CA'";
      var isValid = await us_parks.IsValidDefinitionQuery(sql);
      if (isValid)
      {
        await QueuedTask.Run(() =>
        {
          var def_query = new DefinitionQuery("CaliforniaParks", sql);
    
          us_parks.InsertDefinitionQuery(def_query);
          us_parks.SetDefinitionQuery("STATE_ABBR = 'CA'");
    
          //Set it active
          us_parks.SetActiveDefinitionQuery(def_query.Name);
    
          //or....also - set it active when it is inserted
          //us_parks.InsertDefinitionQuery(def_query, true);
        });
      }
    }
    Apply a Definition Query Filter to a Feature Layer Option 2
    {
      var us_parks = map.GetLayersAsFlattenedList()
            .OfType<FeatureLayer>().First(l => l.Name == "USNationalParks");
    
      var sql = "STATE_ABBR = 'CA'";
      var isValid = await us_parks.IsValidDefinitionQuery(sql);
      if (isValid)
      {
        //inserts a new definition query and makes it active
        //it will be assigned a unique name
        us_parks.SetDefinitionQuery(sql);
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.8 or higher.
    See Also