Share via


How to: Retrieve Rows Using Bookmarks (OLE DB)

The consumer sets the dwFlag field value of the binding structure to DBCOLUMNSINFO_ISBOOKMARK to indicate that the column is used as bookmark. The consumer also sets the rowset property DBPROP_BOOKMARKS to VARIANT_TRUE. This allows column 0 to be present in the rowset. IRowsetLocate::GetRowsAt is then used to fetch rows starting with the row specified an offset from a bookmark.

A complete sample shows how to fetch rows using a bookmark. The complete sample code is in the file GetRowsUsingBookmark.cpp. You can download an archive containing the sample from the SQL Server Downloads page on MSDN. In this sample, the fifth row is retrieved from the result set produced from the execution of a SELECT statement.

This sample was developed using Microsoft Visual C++ 2005.

Security noteSecurity Note

When possible, use Windows Authentication. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 crypto API.

To retrieve rows using bookmarks

  1. Establish a connection to the data source.

  2. Set the rowset DBPROP_IRowsetLocate property to VARIANT_TRUE.

  3. Execute the command.

  4. Set the dwFlag field of the binding structure to DBCOLUMNSINFO_ISBOOKMARK flag for the column that will be used as a bookmark.

  5. Use IRowsetLocate::GetRowsAt to fetch rows, starting with the row specified by an offset from the bookmark.