How to write Memo BLOB to DB using ADO -- how to convert binary to VARIANT 
Author Message
 How to write Memo BLOB to DB using ADO -- how to convert binary to VARIANT

Does anyone have an idea of how to write a BLOB data type (such as the
Memo field in Access) to a database?
The below function works fine for all other types of data, but I'm
experiencing difficulty figuring out how to convert binary data such
as a bmp file to a variant so it can be used in below method.

Is there an ADO routine or otherwise that converts a binary string to
a Variant type? if so this would solve my problem as it could be used
below.

Thanks
Greg

void CADOHelper::OnRecordsetAddnew()
{
        _RecordsetPtr pRecordSet;
        HRESULT hr;
        _bstr_t bstrQuery("SELECT * FROM Products WHERE PartNumber IS NULL");
        _variant_t vNull;      
        vNull.vt = VT_ERROR;
        vNull.scode = DISP_E_PARAMNOTFOUND;
        try
        {
                hr = pRecordSet.CreateInstance(_uuidof(Recordset));
                if (SUCCEEDED(hr))
                {
                        pRecordSet->PutRefActiveConnection(m_spConn);
                        hr = pRecordSet->Open(_variant_t(bstrQuery), vNull,
adOpenForwardOnly, adLockOptimistic, adCmdText);
                        if (SUCCEEDED(hr))
                        {
                                // Create an array for the list of fields in
                                // the Products table.
                                COleSafeArray vaFieldlist;
                                vaFieldlist.CreateOneDim(VT_VARIANT,4);
                                // Fill in the field names now.
                                long lArrayIndex[1];
                                lArrayIndex[0] = 0;
                                vaFieldlist.PutElement(lArrayIndex,
                                        &(_variant_t("PartNumber")));
                                lArrayIndex[0] = 1;
                                vaFieldlist.PutElement(lArrayIndex,
                                        &(_variant_t("ProductName")));
                                lArrayIndex[0] = 2;
                                vaFieldlist.PutElement(lArrayIndex,
                                        &(_variant_t("Price")));
                                lArrayIndex[0] = 3;
                                vaFieldlist.PutElement(lArrayIndex,
                                        &(_variant_t("Greg")));

                                // Create an array for the list of values to go in
                                // the Products table.
                                COleSafeArray vaValuelist;
                                vaValuelist.CreateOneDim(VT_VARIANT,4);
                                // Fill in the values for each field.
                                lArrayIndex[0] = 0;
                                vaValuelist.PutElement(lArrayIndex,
                                        &(_variant_t("8TRACK-003")));
                                lArrayIndex[0] = 1;
                                vaValuelist.PutElement(lArrayIndex,
                                        &(_variant_t("Bell Bottom Hits")));
                                lArrayIndex[0] = 2;
                                vaValuelist.PutElement(lArrayIndex,
                                        &(_variant_t((float)19.95)));
                                pRecordSet->AddNew(vaFieldlist, vaValuelist);
                                pRecordSet->Close();
                        }
                }
        }
    catch( _com_error &e )
    {
                TRACE( "Error:%08lx.\n", e.Error());
                TRACE( "ErrorMessage:%s.\n", e.ErrorMessage());
                TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source()));
                TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description()));
    }
    catch(...)
    {
      TRACE( "\n*** Unhandled Exception ***\n" );
    }

Quote:
}



Fri, 29 Oct 2004 20:11:47 GMT  
 How to write Memo BLOB to DB using ADO -- how to convert binary to VARIANT

Hello,

You may use GetChunk and AppendChunk to read and write BLOB fields. Take a
look at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q189415

Hope this helps.

Regards,
Max
==========================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

|Newsgroups: microsoft.public.vc.database
|Subject: How to write Memo BLOB to DB using ADO  --  how to convert binary
to VARIANT

|
|Does anyone have an idea of how to write a BLOB data type (such as the
|Memo field in Access) to a database?
|The below function works fine for all other types of data, but I'm
|experiencing difficulty figuring out how to convert binary data such
|as a bmp file to a variant so it can be used in below method.
|
|Is there an ADO routine or otherwise that converts a binary string to
|a Variant type? if so this would solve my problem as it could be used
|below.
|
|Thanks
|Greg
|
|
|
|
|void CADOHelper::OnRecordsetAddnew()
|{
|       _RecordsetPtr pRecordSet;
|       HRESULT hr;
|       _bstr_t bstrQuery("SELECT * FROM Products WHERE PartNumber IS NULL");
|       _variant_t vNull;      
|       vNull.vt = VT_ERROR;
|       vNull.scode = DISP_E_PARAMNOTFOUND;
|       try
|       {
|               hr = pRecordSet.CreateInstance(_uuidof(Recordset));
|               if (SUCCEEDED(hr))
|               {
|                       pRecordSet->PutRefActiveConnection(m_spConn);
|                       hr = pRecordSet->Open(_variant_t(bstrQuery), vNull,
|adOpenForwardOnly, adLockOptimistic, adCmdText);
|                       if (SUCCEEDED(hr))
|                       {
|                               // Create an array for the list of fields in
|                               // the Products table.
|                               COleSafeArray vaFieldlist;
|                               vaFieldlist.CreateOneDim(VT_VARIANT,4);
|                               // Fill in the field names now.
|                               long lArrayIndex[1];
|                               lArrayIndex[0] = 0;
|                               vaFieldlist.PutElement(lArrayIndex,
|                                       &(_variant_t("PartNumber")));
|                               lArrayIndex[0] = 1;
|                               vaFieldlist.PutElement(lArrayIndex,
|                                       &(_variant_t("ProductName")));
|                               lArrayIndex[0] = 2;
|                               vaFieldlist.PutElement(lArrayIndex,
|                                       &(_variant_t("Price")));
|                               lArrayIndex[0] = 3;
|                               vaFieldlist.PutElement(lArrayIndex,
|                                       &(_variant_t("Greg")));
|
|                               // Create an array for the list of values to go in
|                               // the Products table.
|                               COleSafeArray vaValuelist;
|                               vaValuelist.CreateOneDim(VT_VARIANT,4);
|                               // Fill in the values for each field.
|                               lArrayIndex[0] = 0;
|                               vaValuelist.PutElement(lArrayIndex,
|                                       &(_variant_t("8TRACK-003")));
|                               lArrayIndex[0] = 1;
|                               vaValuelist.PutElement(lArrayIndex,
|                                       &(_variant_t("Bell Bottom Hits")));
|                               lArrayIndex[0] = 2;
|                               vaValuelist.PutElement(lArrayIndex,
|                                       &(_variant_t((float)19.95)));
|                               pRecordSet->AddNew(vaFieldlist, vaValuelist);
|                               pRecordSet->Close();
|                       }
|               }
|       }
|    catch( _com_error &e )
|    {
|               TRACE( "Error:%08lx.\n", e.Error());
|               TRACE( "ErrorMessage:%s.\n", e.ErrorMessage());
|               TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source()));
|               TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description()));
|    }
|    catch(...)
|    {
|      TRACE( "\n*** Unhandled Exception ***\n" );
|    }
|}
|



Sat, 30 Oct 2004 21:13:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. put a BLOB in a MSAccess DB using straight ODBC

2. Using ADO recordset binding to retrieve BLOBs

3. CDAORecordset & BLOBS/memo fields

4. Insert blob data into oracle using ADO

5. how to access blobs using ADO?

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

7. how to convert a variant to ado recordset?

8. Convert VARIANT * to ADO recordset *

9. how to insert value of BLOB into a memo field

10. Problem writing to BLOB coloumns using DBTYPE_BYTES

11. ADO : pbroblems writing into ORACLE DB

12. Reading and writing BLOBs using DAO

 

 
Powered by phpBB® Forum Software