To set up a program to execute a scrollable cursor
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;
Open the rowset:
IRowset* pIRowset = ds.OpenRowset("book", 1, rgRowsetPropSet);
Fetch the rows forward:
DBCOUNTITEM cRowsReturned; HROW hRow[3]; HROW* pRows = hRow; hr = pIRowset->GetNextRows(NULL, 0, 3, &cRowsReturned, &pRows);
Release the rows:
hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
Fetch the rows backward:
DBCOUNTITEM cRowsReturned; HROW hRow[3]; HROW* pRows = hRow; hr = pIRowset->GetNextRows(NULL, 0, -3, &cRowsReturned, &pRows);
Release the rows:
hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
Release the rowset:
pIRowset->Release()