我在做用vc向oracle中存储blob数据,问题希望大家能帮我一下,我是用system用户名连接的,在system方案下建的表face,现在可以存储可以修改了。但我要存blob类型的数据,他会提示出错[oracle][odbc]Function Sequence error
有人知道是什么原因嘛?先谢了!
源程序如下:
 _RecordsetPtr pRs = NULL;             
  _ConnectionPtr pConnection = NULL;
  _variant_t varChunk;
  HRESULT hr;    try
    {
  
        //Open a connection
        hr=pConnection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
//连接到数据源
           hr=pConnection->Open("DSN=ADOtest","system","ado",0); //连接叫作ADOTest的ODBC数据源 
if(SUCCEEDED(hr)){
hr=pRs.CreateInstance(__uuidof(Recordset));
        hr=pRs->Open("SELECT * FROM ADOTEST",(IDispatch*)pConnection, 
               adOpenDynamic,adLockOptimistic,adCmdText);  //Open a Table
}
if(SUCCEEDED(hr))
{
 
CString str;
CString AppExePath;
char tempath[100];
GetCurrentDirectory(100,tempath);
//AppExePath=tempath;
CFileFind filefind;
//CString datapath=AppExePath+"\\data\\*.bmp";
CString datapath="data\\*.bmp";
BOOL isfind=filefind.FindFile(datapath);
while(isfind)
{
isfind=filefind.FindNextFile();
CFile imagefile;
if(0 == imagefile.Open(filefind.GetFilePath(),CFile::modeRead))
{
  AfxMessageBox("can't open!");
 return;
}
BYTE* pbuf;
long nLength = imagefile.GetLength();
pbuf = new BYTE[nLength+2];
 if(pbuf == NULL)
   return;                             //allocate memory error;
imagefile.Read(pbuf,nLength);          //read the file into memory  BYTE *pBufEx;
 pBufEx = pbuf;
 //build a SAFFERRAY
 SAFEARRAY* psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);   for (long i = 0; i < nLength; i++)
   SafeArrayPutElement (psa, &i, pBufEx++);
  VARIANT varBLOB;
  varBLOB.vt = VT_ARRAY | VT_UI1;
  varBLOB.parray = psa;
pRs->AddNew();        
pRs->Fields->GetItem("Image")->AppendChunk(varBLOB);        
pRs->Update();
}//end while
        pRs->Close();
        pConnection->Close();
}
}
    catch(_com_error &e)
    {
        // Notify the user of errors if any.
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        CString sError;
        sError.Format("Source : %s \n Description : %s\n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
        AfxMessageBox(sError);     
 }

解决方案 »

  1.   

    用BFile来操作,直接插入不认的.
      

  2.   

    vc中我也没用过,在pl/sql里是用bfile来导入的,或者是系统包的过程调用.
      

  3.   

    你可以试试用hextoraw先转到rawbuf里再插入就可以了.
      

  4.   

    你是说不用blob类型了吗?我也是开始接触这东西,我在别的文章里看大家都用的blob类型,这段程序,在由bmp图像向varBLOB转换及插入都是从别人的文章里摘抄的,我觉得不应该有太大问题阿
      

  5.   

    不是不用啊,你的char缓冲直接向blob插入不可以的, 要先转成raw类型啊.
      

  6.   

    vc写数据库我也很菜,你先告诉我vc里怎么声明raw类型的变量吧.
      

  7.   

    不好意思,我也没查到vc里怎么声明raw类型,我这种写法如果写进的是access就好用不过他声明的是image类型