How to insert BLOB data into MSSQL with OLEDB templates library 
Author Message
 How to insert BLOB data into MSSQL with OLEDB templates library

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.


Mon, 18 Mar 2002 03:00:00 GMT  
 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.



Tue, 19 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. OLEDB: Cannot Insert BLOBS when CDataSource out of Proc

2. oledb provider templates & BLOB

3. Accessing BLOB Data with ATL OLEDB Classes

4. Insert blob data into oracle using ADO

5. Saving object OLE into BLOB field in MsSQL

6. OLEDB interfaces vs OLEDB templates

7. ADO vs OLEDB COM vs OLEDB ATL templates

8. How to Operate Oracle BLOB Field Using ADO or OLEDB

9. OLEDB and BLOB's

10. BLOB with OLEDB

11. Inserting Blobs on Informix

12. Insert BLOB into MSAccess.

 

 
Powered by phpBB® Forum Software