Udostępnij za pośrednictwem


Using Bookmarks

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Using Bookmarks.

Before you open the rowset, you must tell the provider that you want to use bookmarks. To do this, set the DBPROP_BOOKMARKS property to true in your property set. The provider retrieves bookmarks as column zero, so you must use the special macro BOOKMARK_ENTRY and the CBookmark class if you are using a static accessor. CBookmark is a template class where the argument is the length in bytes of the bookmark buffer. The length of the buffer required for a bookmark depends on the provider. If you are using the ODBC OLE DB provider, as shown in the following example, the buffer must be 4 bytes.

class CProducts  
{  
public:  
   CBookmark<4>   bookmark;  
  
   BEGIN_COLUMN_MAP(CProducts)  
      BOOKMARK_ENTRY(bookmark)  
   END_COLUMN_MAP()  
};  
  
CDBPropSet propset(DBPROPSET_ROWSET);  
propset.AddProperty(DBPROP_BOOKMARKS, true);  
  
CTable<CAccessor<CProducts> > product;  
product.Open(session, "Products", &propset);  

If you use CDynamicAccessor, the buffer is dynamically allocated at run time. In this case, you can use a specialized version of CBookmark for which you do not specify a buffer length. Use the function GetBookmark to retrieve the bookmark from the current record, as shown in this code sample:

CTable<CDynamicAccessor> product;  
CBookmark<>              bookmark;  
CDBPropSet propset(DBPROPSET_ROWSET);  
  
propset.AddProperty(DBPROP_BOOKMARKS, true);  
product.Open(session, "Products", &propset);  
product.MoveNext();  
product.GetBookmark(&bookmark);  

For information about supporting bookmarks in providers, see Provider Support for Bookmarks.

See Also

Using Accessors