用DAO怎么实现偶不知道,不过DAO都快被淘汰了,楼主就不要用了吧。况且ADO很容易出问题的。这是ODBC中将图片文件存如数据库的代码,有的地方我也不明白:
CString     Sql;
    CFile fileImage;
    CFileStatus fileStatus; if (m_strFileName==_T(""))
return; Sql.Format("select * from [YourImage] where....."); CYourImageSet  * pYourImageSet = new CYourImageSet;    try
    {
        pYourImageSet->Open(AFX_DB_USE_DEFAULT_TYPE,Sql,0);
}
    catch(CException* pE)
    {
        pE->ReportError();
        pE->Delete();
        return;
    }
if (pYourImageSet->GetRecordCount()<=0)
pYourImageSet->AddNew();
else
pYourImageSet->Edit();

    fileImage.Open(m_strFileName, CFile::modeRead);
    fileImage.GetStatus(fileStatus); pYourImageSet->m_Image.m_dwDataLength = fileStatus.m_size;    HGLOBAL hGlobal = GlobalAlloc(GPTR, fileStatus.m_size);
    pYourImageSet->m_Image.m_hData = GlobalLock(hGlobal);    fileImage.ReadHuge(pYourImageSet->m_Image.m_hData, fileStatus.m_size);    pYourImageSet->SetFieldDirty(&pYourImageSet->m_Image);    pYourImageSet->SetFieldNull(&pYourImageSet->m_Image, FALSE);
pYourImageSet->Update();
   
    GlobalUnlock(hGlobal); pYourImageSet->Close();
delete pYourImageSet;

解决方案 »

  1.   

    You create a binary column. You bind a variable of type CLongBinary to that
    column. To write to the database you need to  the recordset's
    corresponding member .. it needs to be SetFieldNull(FALSE) and
    SetFieldDirty(TRUE). LongBinary columns take time to write to a database so
    MFC optimises writing long binaries. It will not write them unless you say
    the field is NOT null and the field is dirty.There are no restrictions on the format. How you interpret the binary data
    is up to you.
      

  2.   

    能不能说的详细点?我刚刚学DAO数据库,好多地方不知道。
    以前的帖子没有所DAO的,是不是大家都不用DAO?
      

  3.   

    重载cdaorecordset 
    重写DoFieldExchange( CFieldExchange* pFX )
    RFX_Binary( pFX, youfieldname, m_pbyte, 300000);//CByteArray *m_pbyte 长度你自己可以定长一些或短一些或动态。