我在做用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);
}
有人知道是什么原因嘛?先谢了!
源程序如下:
_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);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货