Executing scrollable cursors

StepsTo set up a program to execute a scrollable cursor

  1. Set the scrollable cursor properties on the rowset:

    DBPROP RowsetProperties[2];
    for(int i = 0; i < 2; i++)         VariantInit(&RowsetProperties[i].vValue);RowsetProperties[0].dwPropertyID = DBPROP_CANFETCHBACKWARDS;
    RowsetProperties[0].vValue.vt     = VT_BOOL;
    RowsetProperties[0].vValue.boolVal= VARIANT_TRUE;
    RowsetProperties[0].dwOptions = DBPROPOPTIONS_REQUIRED;
    RowsetProperties[0].colid         = DB_NULLID;
    RowsetProperties[1].dwPropertyID  = DBPROP_CANSCROLLBACKWARDS;
    RowsetProperties[1].vValue.vt     = VT_BOOL;
    RowsetProperties[1].vValue.boolVal= VARIANT_TRUE;
    RowsetProperties[1].dwOptions     = DBPROPOPTIONS_REQUIRED;
    RowsetProperties[1].colid         = DB_NULLID;DBPROPSET rgRowsetPropSet[1];
    rgRowsetPropSet[0].guidPropertySet = DBPROPSET_ROWSET;
    rgRowsetPropSet[0].cProperties    = 2;
    rgRowsetPropSet[0].rgProperties = RowsetProperties;
    
  2. Open the rowset:

    IRowset* pIRowset = ds.OpenRowset("book", 1, rgRowsetPropSet);
    
  3. Fetch the rows forward:

    DBCOUNTITEM cRowsReturned;
    HROW hRow[3];
    HROW* pRows = hRow;
    hr = pIRowset->GetNextRows(NULL, 0, 3, &cRowsReturned, &pRows);
    
  4. Release the rows:

    hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
    
  5. Fetch the rows backward:

    DBCOUNTITEM cRowsReturned;
    HROW hRow[3];
    HROW* pRows = hRow;
    hr = pIRowset->GetNextRows(NULL, 0, -3, &cRowsReturned, &pRows);
    
  6. Release the rows:

    hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
    
  7. Release the rowset:

    pIRowset->Release()