
How to insert BLOB data into MSSQL with OLEDB templates library
Example of how to UPDATE a blob field containing wave data.
// Specific buffer memory details deleted...
// CISSHelper class is from MSDN Aotblob example.
// Stuff data into ISequentialStream helper class.
CISSHelper ISSHelper;
hr = ISSHelper.Write( pWaveData, dwSize, NULL );
if ( FAILED(hr) )
{
DisplayOLEDBErrorRecords( hr );
return hr;
}
// Clean up memory handle for WAV and null pData so we don't delete
it later.
::GlobalUnlock( hMemDest );
::GlobalFree( hMemDest );
pWaveData = NULL;
// Open rowset's session object using our initialized data source
object.
CString csSQL;
csSQL.Format("SELECT * FROM MyTable WHERE PID = %d;", nPID );
// CMyTable class generated using VC6 consumer templates.
CMyTable cmd;
hr = cmd.Open( m_DataSource, csSQL );
if ( FAILED(hr) )
{
DisplayOLEDBErrorRecords( hr );
return hr;
}
hr = cmd.MoveFirst();
if( FAILED(hr) ) // This can return DB_S_ENDOFROWSET which is not a
failure.
{
DisplayOLEDBErrorRecords( hr );
return hr;
}
// Release existing STGM_READ ISequentialStream pointer if one is
given to us by provider.
if( DBSTATUS_S_OK == cmd.m_AudioBlob_Status )
cmd.m_AudioBlob->Release();
// Ignore autonumber fields
cmd.m_ulPIDStatus = DBSTATUS_S_IGNORE;
// Setup other fields here...
// Set ISequentialStream pointer to our implementation.
cmd.m_AudioBlob = (ISequentialStream*) &ISSHelper;
// Set length field and status (required by some providers).
cmd.m_AudioBlob_Length = ISSHelper.m_ulLength;
cmd.m_AudioBlob_Status = DBSTATUS_S_OK;
// Call SetData to trigger update.
hr = cmd.SetData();
if( FAILED(hr) )
{
DisplayOLEDBErrorRecords( hr );
return hr;
}
// Close rowset.
cmd.FreeRecordMemory();
cmd.Close();
Quote:
> I transfered my database from MsAccess to MsSQL. In my program I am make
> changes of database classes from DAO to OLE DB template. My problem is in
> working with BLOB data. I can read it from database, but can't see the
> simple way to transfer new and changed data back. For the known type BLOB
> field I use CAccessor and ISequentialStream. Tell me please, what should I
> do for updating and inserting operation. The best way is to get a sample in
> OLE DB templates or advise how to do it.