Using Scrollable Cursors

    To use cursors
  1. Call SQLNumResultCols to get the number of columns (C) in the rowset.
  2. Call SQLSetStmtOption with an fOption of SQL_ROWSET_SIZE to set the number of rows (R) in the rowset.
  3. Optionally, call SQLSetCursorName to set the cursor name or SQLGetCursorName to get the cursor name.
  4. Use column-wise binding.

    Or

    Use row-wise binding. For more information, see Using Rowset Binding.

  5. Fetch rowsets from the cursor as desired. For more information, see Fetching and Updating Rowsets.
  6. Call SQLMoreResults to determine if another result set is available.

    If it returns SQL_SUCCESS, another result set is available.

    If it returns SQL_NO_DATA_FOUND, no more result sets are available.

    If it returns SQL_SUCCESS_WITH_INFO or SQL_ERROR, call SQLError to determine if the output from a PRINT or RAISEERROR statement is available.

    If bound statement parameters are used for output parameters or the return value of a stored procedure, use the data now available in the bound parameter buffers.

    Note that when a result set contains compute rows, each compute row is made available as a separate result set. These compute result sets are interspersed within the normal rows and break up the normal rows into multiple result sets.

  7. Call SQLFreeStmt with an fOption of SQL_UNBIND to release all the bound column buffers.
  8. If another result set is available, go to step 1.