How to use a statement (ODBC)

To use a statement

  1. Call SQLAllocHandle with a HandleType of SQL_HANDLE_STMT to allocate a statement handle.
  2. Optionally, call SQLSetStmtAttr to set statement options or SQLGetStmtAttr to get statement attributes.

    To use server cursors, you must set cursor attributes to values other than their defaults.

  3. Optionally, if the statement will be executed several times, prepare the statement for execution with SQLPrepare.
  4. Optionally, if the statement has bound parameter markers, bind the parameter markers to program variables by using SQLBindParameter. If the statement was prepared, you can call SQLNumParams and SQLDescribeParam to find the number and characteristics of the parameters.
  5. Execute a statement directly by using SQLExecDirect.

    Or

    If the statement was prepared, execute it multiple times by using SQLExecute.

    Or

    Call a catalog function, which returns results.

  6. Process the results by binding the result set columns to program variables, by moving data from the result set columns to program variables by using SQLGetData, or a combination of the two methods.

    Fetch through the result set of a statement one row at a time.

    Or

    Fetch through the result set several rows at a time by using a block cursor.

    Or

    Call SQLRowCount to determine the number of rows affected by an INSERT, UPDATE, or DELETE statement.

    If the SQL statement can have multiple result sets, call SQLMoreResults at the end of each result set to see if there are additional result sets to process.

  7. After results are processed, the following actions may be necessary to make the statement handle available to execute a new statement:
  8. Call SQLFreeHandle with a HandleType of SQL_HANDLE_STMT to free the statement handle.
See Also
Allocating a Statement Handle SQLFreeHandle
Constructing an SQL Statement SQLGetStmtAttr
Direct Execution SQLRowCount
Freeing a Statement Handle SQLSetStmtAttr
Prepared Execution SQLBindParameter
SQLDescribeParam SQLGetData
SQLRowCount SQLMoreResults

  


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