Export (0) Print
Expand All

Commands

SQL Server 2000

Commands

In OLE DB, a command object is used to execute provider-specific text commands, similar to SQL statements. The basic steps for using commands in OLE DB are:

  1. A command object is created from an existing session object using IDBCreateCommand::CreateCommand.
  2. The command text for the query is specified using ICommandText.

    The command syntax supported by the OLE DB Provider for Microsoft® SQL Server™ 2000 Windows® CE Edition (SQL Server CE) is specified as DBGUID_SQL. DBGUID_SQL syntax is primarily SQL-92 syntax with ODBC escape sequences.

  3. The command is executed using ICommand::Execute.

SQL Server CE supports a subset of the SQL Server Transact-SQL query grammar. Queries that can usually be run on SQL Server CE can also run on SQL Server 2000; however, many of the features of Transact-SQL are absent from SQL Server CE and only a single SQL statement can be executed in a command.

SQL Server CE supports parameterized queries in which parameters are delimited with the question mark (?) character; however, named parameterized queries and output parameters for queries are not supported. For more information about the query grammar supported by SQL Server CE, see SQL Reference for SQL Server CE.

Preparing Commands

To be able to execute a query, the database engine must first parse, compile, and optimize the SQL statement. Often, this work can be done once if the command is to be executed multiple times, potentially saving time. If clients expect to run a query more than once, it is recommended that the command be prepared once, then call Execute multiple times. This should maximize performance by avoiding query recompilation. Commands can be prepared prior to execution by calling ICommandPrepare::Prepare. This is equivalent to compiling the command.

Examples

For examples of creating and executing commands using the OLE DB Provider for SQL Server CE, see the example in Parameters or the Employees.cpp file in the NorthwindOLEDB sample that ships with SQL Server CE.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft