The ICommandText::Execute() function prepares and executes a SQL statement. The code samples in this section describe how to execute a statement without parameters. Optionally, the statement can include parameters.
Executing a statement without parameters
Obtain a Command object from the session:
ICommandText* pICommandText; hr = pIDBCreateCommand->CreateCommand( NULL, IID_ICommandText, (IUnknown**)&pICommandText);
Set the SQL statement the command will execute:
hr = pICommandText->SetCommandText( DBGUID_DBSQL, L"DELETE FROM publishers where pub_id = '7777' ");
Execute the command. The cRowsAffected
contain
the number of rows inserted, deleted, or updated by the command.
The pIRowset
is assigned to
the Rowset object created by the command, as
shown:
DBROWCOUNT cRowsAffected; IRowset* pIRowset; hr = pICommandText->Execute( NULL, IID_IRowset, NULL, &cRowsAffected, (IUnknown**)&pIRowset);