How to: Set Large Data (OLE DB)

New: 14 April 2006

To pass a pointer to its own storage object, the consumer creates an accessor that binds the value of the BLOB column and then calls the IRowsetChange::SetData or IRowsetChange::InsertRow methods.

To set BLOB data
  1. Create a DBOBJECT structure describing how the BLOB column should be accessed. Set the dwFlag element of the DBOBJECT structure to STGM_READ and set the iid element to IID_ISequentialStream (the interface to be exposed).

  2. Set the properties in the DBPROPSET_ROWSET property group so the rowset is updatable.

  3. Create a set of bindings (one of each column) by using an array of DBBINDING structures. Set the wType element in the DBBINDING structure to DBTYPE_IUNKNOWN, and the pObject element to point to the DBOBJECT structure you created.

  4. Create an accessor using the binding information in the DBBINDINGS array of structures.

  5. Call GetNextRows to fetch next rows into the rowset. Call GetData to read the data from the rowset.

  6. To set the data, create a storage object containing the data (and also the length indicator), and then call IRowsetChange::SetData (or IRowsetChange::InsertRow) with the accessor that binds the BLOB column.

The complete sample code is in the file WorkingWithBLOBs.cpp. You can download an archive containing the sample from the SQL Server Downloads page on MSDN.

This sample was developed using Microsoft Visual C++ 2005.,SQL.90).gifSecurity 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.

Community Additions