高手们啊,help!!

Only_01 2008-12-27 01:16:15
void CtempDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
::CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Hotel.mdb","","",adModeUnknown);
pRst=pConn->Execute("select * from hotel",NULL,adCmdText);
if(!pRst->adoEOF)
{
pRst->Update();//如果有这句话,就会出现 Runtime library错误。如果没事,就可以运行
}
::CoUninitialize();
}
高手帮一下,好几天了也没解决啊,愁啊
...全文
138 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bfhtian 2008-12-27
  • 打赏
  • 举报
回复
up
oyljerry 2008-12-27
  • 打赏
  • 举报
回复
Update前总要修改一下数据什么的...
1. VC把一个文件存入数据库

CFile imagefile;
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->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 Description : %s",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
AfxMessageBox(sError);
}
lsd1025 2008-12-27
  • 打赏
  • 举报
回复
ADO连接数据库吧,
连接数据库,创建记录集打开表等最好分开封装成函数吧!
感觉你全部放在这里这样用感觉不太好的,找个正规的数据库的程序了解一下处理放置布局吧,
你这样感觉不是很好的。
星羽 2008-12-27
  • 打赏
  • 举报
回复
Open 和 Execute 判断一下成功了没
wiowei 2008-12-27
  • 打赏
  • 举报
回复
给你个蛮好ADO例子参考吧:http://www.yesky.com/277/1893277.shtml
wiowei 2008-12-27
  • 打赏
  • 举报
回复
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
为何都没有创建对象:

// 创建Connection对象
pConn.CreateInstance("ADODB.Connection");
// 创建记录集对象
pRst.CreateInstance(__uuidof(Recordset));

另外open之后加个语句看有没有成功:

if(pConn==NULL)
   cerr<<"Lind data ERROR!n";
Only_01 2008-12-27
  • 打赏
  • 举报
回复
呵呵。谢谢啊
sincor 2008-12-27
  • 打赏
  • 举报
回复
学习 帮你顶 让高手 看到 这里面有高手 肯定能解决你的问题

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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