Commands and Tables


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at Commands and Tables.

Commands and tables allow you to access rowsets; that is, open rowsets, execute commands, and bind columns. The CCommand and CTable classes instantiate the command and table objects, respectively. These classes derive from CAccessorRowset as shown in the following figure.

CCommand and CTable
Command and Table Classes

In the previous table, TAccessor can be any accessor type listed in Accessor Types. TRowset can be any rowset type listed in Rowset Types. TMultiple specifies the result type (a single or multiple result set).

The ATL OLE DB Consumer Wizard lets you specify whether you want a command or table object.

  • For data sources without commands, you can use the CTable class. You generally use it for simple rowsets that specify no parameters and require no multiple results. This simple class opens a table on a data source using a table name that you specify.

  • For data sources that support commands, you can use the CCommand class instead. To execute a command, call Open on this class. As an alternative, you can call Prepare to prepare a command that you want to execute more than once.

    CCommand has three template arguments: an accessor type, a rowset type, and a result type (CNoMultipleResults, by default, or CMultipleResults). If you specify CMultipleResults, the CCommand class supports the IMultipleResults interface and handles multiple rowsets. The DBVIEWER sample shows how to handle the multiple results.

OLE DB Consumer Templates