Export (0) Print
Expand All

Executing a Command

SQL Server 2000

After the connection to a data source is established, the consumer calls the IDBCreateSession::CreateSession method to create a session. The session acts as a command, rowset, or transaction factory.

To work directly with individual tables or indexes, the consumer requests the IOpenRowset interface. The IOpenRowset::OpenRowset method opens and returns a rowset that includes all rows from a single base table or index.

To execute a command (such as SELECT * FROM Authors), the consumer requests the IDBCreateCommand interface. The consumer can execute the IDBCreateCommand::CreateCommand method to create a command object and request for the ICommandText interface. The ICommandText::SetCommandText method is used to specify the command that is to be executed.

The Execute command is used to execute the command. The command can be any SQL statement, procedure name, and so on. Not all commands produce a result set (rowset) object. Commands such as SELECT * FROM authors produce a result set.

OLE DB Extensions for XML

The ICommandText::SetCommandText and ICommand::Execute statements can be used to set XML documents as command text, execute the command, and retrieve the result as a stream, which can then be used in further processing, such as passing the XML to the Document Object Model (DOM).

Templates are valid XML documents that contain one or more SQL command tags. These XML templates can be passed to ICommandText::SetCommandText. When XML templates are set as command text using ICommandText::SetCommandText, the consumer must pass DBGUID_MSSQLXML as the globally unique identifier (GUID) of the command syntax. This GUID indicates that the command text is an XML template.

The consumer must call ICommand::Execute to execute XML templates. To obtain XML documents as a result set, riid must be set to IStream.

Show:
© 2015 Microsoft