ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data Namespace / Database Class / OpenTable Method
The QueryDescription object.
Example

In This Topic
    OpenTable Method (Database)
    In This Topic
    Gets the Table or FeatureClass (if it is spatially enabled) associated with queryDescription. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function OpenTable( _
       ByVal queryDescription As QueryDescription _
    ) As Table

    Parameters

    queryDescription
    The QueryDescription object.

    Return Value

    The Table or FeatureClass (if it is spatially enabled) associated with queryDescription.
    Exceptions
    ExceptionDescription
    queryDescription is null.
    A database-related exception has occurred.
    Remarks
    A QueryDescription object fully describes how a single database table or one or more database tables (specified by a valid SQL SELECT statement) should be represented as a Table or FeatureClass if the table is spatially enabled. Essentially, there are two flavors of QueryDescription. The first is created by GetQueryDescription(String). Given a table name (fully qualified or unqualified), it encapsulates all the important properties that describe the underlying single table (i.e., QueryDescription.IsQueryLayer returns false). The second flavor is created by GetQueryDescription(String,String). Given a valid SQL SELECT statement and a query layer name, it encapsulates all the important properties that describe the underlying query layer that is created from one or more tables (i.e., QueryDescription.IsQueryLayer returns true). If the table returned is a FeatureClass, the spatial type is taken from the first row returned. To remove ambiguity, QueryDescription.SetShapeType should be called prior to calling this routine.
    Example
    Create Default QueryDescription for a Database table and obtain the ArcGIS.Core.Data.Table for the QueryDescription
    public async Task DefaultQueryDescription()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        DatabaseConnectionProperties databaseConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
        {
          AuthenticationMode = AuthenticationMode.DBMS,
          Instance = "instance",
          Database = "database",
          User = "user",
          Password = "password"
        };
    
        using (Database database = new Database(databaseConnectionProperties))
        {
          QueryDescription queryDescription = database.GetQueryDescription("CUSTOMERS");
    
          using (Table table = database.OpenTable(queryDescription))
          {
            //use table
          }
        }
      });
    }
    Create QueryDescription from a custom query for a Database table
    public async Task CustomQueryDescription()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        DatabaseConnectionProperties databaseConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
        {
          AuthenticationMode = AuthenticationMode.DBMS,
          Instance = "instance",
          Database = "database",
          User = "user",
          Password = "password"
        };
    
        using (Database database = new Database(databaseConnectionProperties))
        {
          QueryDescription queryDescription = database.GetQueryDescription("SELECT OBJECTID, Shape, FACILITYID FROM EmergencyFacility WHERE JURISDICT = 'Municipal'", "MunicipalEmergencyFacilities");
    
          using (Table table = database.OpenTable(queryDescription))
          {
            // Use the table.
          }
        }
      });
    }
    Create QueryDescription from a query for an SQLite Database table
    public async Task SqliteQueryDescription()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Database database = new Database(new SQLiteConnectionPath(new Uri("Path\\To\\Sqlite\\Database\\USA.sqlite"))))
        {
          QueryDescription washingtonCitiesQueryDescription = database.GetQueryDescription("select OBJECTID, Shape, CITY_FIPS, CITY_NAME, STATE_FIPS, STATE_CITY, TYPE, CAPITAL from main.cities where STATE_NAME='Washington'", "WashingtonCities");
    
          using (Table washingtonTable = database.OpenTable(washingtonCitiesQueryDescription))
          {
            // Use washingtonTable.
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also