正文

使用vc ADO访问access数据库统一模版2007-08-27 10:37:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sword2008/28875.html

分享到:

 直接复制过去修改就可以使用.要读读程序理解一下. //======================================================= _ConnectionPtr m_pConnection; //定义连接 CoInitialize(NULL);//初始化 m_pConnection.CreateInstance(__uuidof(Connection));     try                     {             // 打开本地Access库db1.mdb         m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data       Source=db1.mdb","","",adModeUnknown);//注意mdb1.mdb的保存位置             } catch(_com_error e) { AfxMessageBox("connect error"); }  _RecordsetPtr m_pRecordset; m_pRecordset.CreateInstance(__uuidof(Recordset));  try {      m_pRecordset->Open("SELECT * FROM table1",        m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针  dOpenDynamic,  adLockOptimistic,  adCmdText); } catch(_com_error *e) {  AfxMessageBox("get recordset error"); }  _variant_t var;  CString str1,str2,str3; try {  if(!m_pRecordset->BOF)   m_pRecordset->MoveFirst();//移动到第一个记录  else  {   AfxMessageBox("no data");  }          while(!m_pRecordset->adoEOF)         {   var=m_pRecordset->GetCollect("id");   if(var.vt != VT_NULL)                  str1= _com_util::ConvertBSTRToString((_bstr_t)var);   var = m_pRecordset->GetCollect("name");              if(var.vt != VT_NULL)                      str2=_com_util::ConvertBSTRToString((_bstr_t)var);   var = m_pRecordset->GetCollect("score");              if(var.vt != VT_NULL)                      str3=_com_util::ConvertBSTRToString((_bstr_t)var);   AfxMessageBox(str1+"|"+str2+"|"+str3);                      m_pRecordset->MoveNext();         }     } catch(_com_error *e)     {         AfxMessageBox("operate error");     }   http://www.ednchina.com/blog/yoyowind/29532/message.aspx

阅读(3749) | 评论(3)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册