BOOL CAIASPDoc::DB_Insert(CAIImg* imgDeposit, CFile &file)
{
try
{
m_pRecordset->Open(_variant_t("ai_img"), m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdTable); //打开ai_img表
m_pRecordset->AddNew(); //新增一条记录
//写入每个字段的值
m_pRecordset->PutCollect("FILE_NAME",_variant_t(imgDeposit->fileName));
m_pRecordset->PutCollect("IMG_SOURCE", _variant_t(imgDeposit->imgSource));
//...
//向img_data字段添加数据
long length = (long)file.GetLength();
BYTE* pbuf = new BYTE[length];
if(pbuf != NULL && file.Read(pbuf, length) == (DWORD)length)
{
MyAppendChunk(m_pRecordset->GetFields()->GetItem("img_data"), pbuf, length);
}
m_pRecordset->Update(); //添加记录
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
m_pRecordset->Close();
return FALSE;
}
m_pRecordset->Close();
return TRUE;
}
就是这个函数,我用循环调用他,但总是成功一次失败一次这样间隔着来,失败的时候就报“多步 OLE DB 操作产生错误。 如果可能,请检查每个 OLE DB 状态值。没有工作被完成。”这个错误。求大神们帮帮忙!