Executing Queries

After an ODBC application initializes a connection handle and connects with a data source, it allocates one or more statement handles on the connection handle. The application can then execute SQL statements on the statement handle. The general sequence of events in executing an SQL statement is:

  1. Set any needed statement attributes.
  2. Construct the statement.
  3. Execute the statement.
  4. Retrieve any result sets.

After an application retrieves all of the rows in all of the result sets returned by the SQL statement, it can execute another query on the same statement handle. If an application determines that it does not need to retrieve all of the rows in a particular result set, it can cancel the remainder of the result set by calling either SQLMoreResults or SQLCloseCursor.

If, in an ODBC application, you need to execute the same SQL statement multiple times with different data, you can use a parameter marker, which is denoted by a question mark (?), in the construction of an SQL statement:

INSERT INTO MyTable VALUES (?, ?, ?)

  

Each parameter marker can then be bound to a program variable by calling SQLBindParameter.

After all SQL statements have been executed and their result sets processed, the application frees the statement handle.

The Microsoft® SQL Server™ ODBC driver supports multiple statement handles per connection handle. Transactions are managed at the connection level, so all work done on all statement handles on a single connection handle are managed as part of the same transaction.

See Also
SQLBindParameter SQLCloseCursor
SQLMoreResults  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.