Deleting rows in a rowset with SQLSetPos()

You can use SQLSetPos() to delete any row in a rowset. SQLSetPos() operates on your current rowset through a dynamic cursor.

Before you begin

Before you can call SQLSetPos(), you must call SQLFetch() or SQLFetchScroll().

Procedure

to delete rows with SQLSetPos():

Call SQLSetPos() with Operation set to SQL_DELETE and RowNumber set to the number of the row to delete.
If you set RowNumber to 0, all rows in the rowset are deleted.

If you set RowNumber to 0, but you want to delete only certain rows, you can disable the delete of the other rows by setting the corresponding elements of the row operation array that is pointed to by the SQL_ATTR_ROW_OPERATION_PTR statement attribute to SQL_ROW_IGNORE.

Example

The following example is an application that uses SQLSetPos() to delete a row in table CUSTOMER.
#define ROWSET_SIZE 10
/* declare and initialize local variables        */
SQLCHAR sqlstmt[] =
  "SELECT Cust_Num, First_Name, Last_Name FROM CUSTOMER";
/* Set up dynamic cursor type                    */
rc = SQLSetStmtAttr(hstmt,
  SQL_ATTR_CURSOR_TYPE,
  (SQLPOINTER) SQL_CURSOR_DYNAMIC,
  0);
/* Set pointer to row status array               */
rc = SQLSetStmtAttr(hstmt,
  SQL_ATTR_ROW_STATUS_PTR,
  (SQLPOINTER) rowStatus,
  0);
/* Set number of rows to fetch                   */
rc = SQLSetStmtAttr(hstmt,
  SQL_ATTR_ROW_ARRAY_SIZE,
  (SQLPOINTER) ROWSET_SIZE,
  0);
/* Fetch first rowset                            */
rc = SQLFetchScroll(hstmt, SQL_FETCH_FIRST, 0);
/* Delete first row in rowset                    */
rc = SQLSetPos(hstmt, 1, SQL_DELETE, SQL_LOCK_NO_CHANGE);