使用MFC DAO处理数据库的OLE对象,其变量类型为CLongBinary,比如我想将一个a.bmp文件嵌入,需要如何处理,谢谢!

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/836/836657.xml?temp=.9883386
      

  2.   

    谢谢!我看了http://www.csdn.net/expert/topic/836/836657.xml?temp=.9883386处的内容。很有帮助,但我还是有不明之处。我用的是DAO,
    其中:CLongBinary m_Figure;
    程序如下:
        CFile   fileImage;
        CFileStatus fileStatus;
        fileImage.Open("e:\\1.bmp", CFile::modeRead);
        fileImage.GetStatus(fileStatus); if(m_pSet->IsOpen())m_pSet->Close();
    m_pSet->Open();

    m_pSet->Edit();

    m_pSet->m_Figure.m_dwDataLength=fileStatus.m_size;
    HGLOBAL hGlobal= GlobalAlloc(GPTR,fileStatus.m_size);
    m_pSet->m_Figure.m_hData=GlobalLock(hGlobal);
    fileImage.ReadHuge(m_pSet->m_Figure.m_hData,fileStatus.m_size);
    m_pSet->SetFieldDirty(&m_pSet->m_Figure);
    m_pSet->SetFieldNull(&m_pSet->m_Figure,FALSE);
    m_pSet->Update();
    GlobalUnlock(hGlobal);
             m_pSet->Close();
    在数据库中显示为: 长二进制数据,好像正常应该显示为:位图图像
    并且双击不能正常链接。
    如果成功解决,我再加分。
      

  3.   

    CODBCFieldInfo fi;
    GetODBCFieldInfo( i, fi );
    fi 的结构在msdn中有说明
      

  4.   

    向Access中插入.bmp文件。我希望插入后,在Access中可以双击打开。但是现在插入后,却不能打开。我感觉好像在程序中应该加一项,标明该OLE对象是位图文件。
    以下是我的程序(ADO),希望高手们指点。        //打开Recordset 
    m_pRecordset.CreateInstance("ADODB.Recordset");
    Fields* fields=NULL;
    hr=m_pRecordset->Open(/*tablename*/"select * from Cuiq","Provider=Microsoft.Jet.OLEDB.3.51.0;Data Source=E:\\mm\\cuiq\\cuiq.mdb",adOpenDynamic,adLockOptimistic,adCmdText);
    hr=m_pRecordset->get_Fields(&fields);
            
            //读入*.bmp文件
    CFile fileImage;
            fileImage.Open("e:\\1.bmp", CFile::modeRead);
    long m_nFileLen=fileImage.GetLength();
    char *pBuf=new char[m_nFileLen];
            fileImage.ReadHuge(pBuf,m_nFileLen);        //把bmp文件加入数据库中的OLE对象段,段名为“Figure”
    VARIANT varBLOB;
    SAFEARRAY *psa; 
    SAFEARRAYBOUND rgsabound[1];
    m_pRecordset->AddNew();  if(pBuf)
    {
    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = m_nFileLen;
    psa = SafeArrayCreate(VT_UI1, 1, rgsabound); ///创建SAFEARRAY对象
    for (long i = 0; i < (long)m_nFileLen; i++)
    {
    SafeArrayPutElement (psa, &i, pBuf++); ///将pBuf指向的二进制数据保存到SAFEARRAY对象psa中 
    }
    varBLOB.vt = VT_ARRAY | VT_UI1;///将varBLOB的类型设置为BYTE类型的数组
    varBLOB.parray = psa; ///为varBLOB变量赋值
    fields->GetItem("Figure")->AppendChunk(varBLOB);
    m_pRecordset->Update();
    }
    m_pRecordset->Close();
    m_pConnection->Close();
      

  5.   

    http://www.csdn.net/expert/topic/849/849925.xml?temp=.469021
      

  6.   

    如果在ACCESS众手动插入图片, 即在ACCESS菜单上 插入-对象-bmp图片,所得的图片在ACCESS中双击即可打开。但是我上面写的程序在ACCESS中双击却无法打开,我不知道在程序中缺了什么?谢谢!
      

  7.   

    AfxOleInit();
    OleInitialize();
      

  8.   

    程序中已经加了AfxOleInit()。在ACCESS中,显示的是"长二进制文件",双击不能打开