想用ADO的如下两个变量,需要做哪些预操作,设置或Include等,我怎么用不了

zhouyongliang 2003-09-11 12:02:43
_ConnectionPtr mCP;
_RecordsetPtr mRP;
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2003-09-11
  • 打赏
  • 举报
回复
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
int main(int argc, char* argv[])
{
printf("This sample shows you how to access BLOB via ADO and store it as file"
"The second field of the database is BLOB\n"
"If it works, it is writen by masterz,\n"
"otherwise I don't know who write it\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
_variant_t varBLOB;
pConn->Open(_bstr_t("Driver={Microsoft Access Driver (*.mdb)};DBQ=GetChunk.mdb"),"","",adConnectUnspecified);
pRst->Open(_bstr_t("BlobTable"),_variant_t((IDispatch *) pConn, true),
adOpenKeyset, adLockOptimistic, adCmdTable);
pRst->MoveFirst();
//long lDataLength = pRst->Fields->Item[1L]->ActualSize;
//varBLOB = pRst->Fields->Item[1L]->GetChunk(lDataLength);
_StreamPtr stream;
stream.CreateInstance("ADODB.Stream");
_variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
stream->raw_Open(varOptional, adModeUnknown, adOpenStreamUnspecified,NULL,NULL);
stream->put_Type(adTypeBinary);
stream->Write(pRst->GetFields()->GetItem(_variant_t((long)1))->GetValue());
stream->SaveToFile("test.txt",adSaveCreateOverWrite);
printf("save stream to file finished\n");
stream->Close();
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
wangshewei 2003-09-11
  • 打赏
  • 举报
回复
在程序代码中加入
#import ...\msado20.dll或msado15.dll;
...为msado.dll的路径。
然后,就可以使用上述的智能指针了。

当加入上述代码后,在程序编译后,会在程序的路径下声称几个文件,文件名不记得了,后缀为.c,在这些文件中有_ConnectionPtr和_RecordsetPtr的声明。这些程序不用自己加入工程中,系统会为你加入。

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧