用INSERT 或是用ADO的插入语句 该怎么写啊,存成image
或binary都行 ,很急啊
或binary都行 ,很急啊
解决方案 »
- 下面的timer用的怎么不对?用真心谢你,本意是把b文件定时拷贝到a文件,结果没拷贝上
- 我编的某个程序比较耗资源,我能否限定这个程序只能使用cpu的50%(比如)
- 通过年月日怎么得到该日是一年中的第几个星期???
- 请帮忙!关于MAINFORM与VIEW的一个问题
- 怎样在状态栏中添加一个时间显示
- 怎么让对话框自动调用OnSize()???
- 接收串口16进制数据设置计算机时间,急!!!!!!!!!!
- 关于ATL中_Module.Init(NULL, NULL);和_Module.Term();的用法?
- vc 中的工程中再添加源文件时,为什么会出现.......?
- FormulaOne 表格控件的使用文题
- 关于托盘图标上菜单及时更正的问题?
- 继“软件打包”,大家再来讨论一下“操作系统版本影响编程”的问题,UP也有分哈!
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
m_pRecordset->AddNew();
m_pRecordset->PutCollect("username",_variant_t(m_UserName));
m_pRecordset->PutCollect("old",atol(m_Old));
if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = m_nFileLen;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
for (long i = 0; i < (long)m_nFileLen; i++)
SafeArrayPutElement (psa, &i, pBuf++);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
m_pRecordset->GetFields()->GetItem("photo")->AppendChunk(varBLOB);
}
if(0 == imagefile.Open("d:\\user\\bmp.bmp",CFile::modeRead))
return;
_RecordsetPtr pRs = NULL;
_ConnectionPtr pConnection = NULL;
_variant_t varChunk;
HRESULT hr;
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; _bstr_t strCnn("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER");
try
{
//Open a connection
pConnection.CreateInstance(__uuidof(Connection));
hr = pConnection->Open(strCnn,"","",NULL); //Connect a DataBase
pRs.CreateInstance(__uuidof(Recordset));
pRs->Open("CustomInfo",_variant_t((IDispatch *) pConnection,true),adOpenKeyset,adLockOptimistic,adCmdTable); //Open a Table
// pRs->AddNew();
pRs->Fields->GetItem("Image")->AppendChunk(varBLOB);
pRs->Update();
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);
}
http://www.vckbase.com/document/viewdoc.asp?id=252上写没问题,可读的
时候
long lDataSize = m_pRecordset->GetFields()->GetItem("photo")->ActualSize;///得到数据的长度
if(lDataSize > 0)
{
_variant_t varBLOB;
varBLOB = m_pRecordset->GetFields()->GetItem("photo")->GetChunk(lDataSize);
if(varBLOB.vt == (VT_ARRAY | VT_UI1)) ///判断数据类型是否正确
{
char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf); ///得到指向数据的指针
/*****在这里我们可以对pBuf中的数据进行处理*****/
SafeArrayUnaccessData (varBLOB.parray);
}
}里 varBLOB = m_pRecordset->GetFields()->GetItem("photo")->GetChunk(lDataSize);
这句报错,有谁知道错那了啊
你仔细跟踪调试一下,看看是不是数据库里的设置有问题!