VC中用ADO连接2010版office的access的数据库是错误提示找不到文件夹怎么办?我写的代码:

[复制链接]
查看11 | 回复2 | 2011-5-1 12:48:11 | 显示全部楼层 |阅读模式
voidCAOD1Dlg::OnButton1()
{
//TODO:Addyourcontrolnotificationhandlercodehere
USES_CONVERSION;
::CoInitialize(NULL);
_ConnectionPtrcon(__uuidof(Connection));
_RecordsetPtrrst(__uuidof(Recordset));
_CommandPtrcmd(__uuidof(Command));
try{
con-Open((\"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C://Example.accdb\"),\"\",\"\",adModeUnknown);
}
catch(_com_errore)
{
AfxMessageBox(\"Sorry\"e.Description());
}
rst-Open(_variant_t(\"select*frominfo_reader\"),
_variant_t((IDispatch*)con),adOpenDynamic,
adLockOptimistic,-1);

while(!rst-adoEOF)
{
m_list.AddString(W2A(rst-GetCollect(_variant_t(\"name\")).bstrVal));
rst-MoveNext();
}
//rst-Close();
//con-Close();
}
回复

使用道具 举报

千问 | 2011-5-1 12:48:11 | 显示全部楼层
楼主可以把数据库文件添加到DSN试试









<h4class=\"ask\">追问


额。。DSN要ODBC的数据源。。这次要求是要用ADO连接数据库的。。一直连不上。。敢情大虾再帮我看下。谢谢了啊
回复

使用道具 举报

千问 | 2011-5-1 12:48:11 | 显示全部楼层
其实VC我没接触过,用过C#和labview,我用labview连接access用的是ODBC。
VC连接access的建议你在网上搜一下,资料挺多的
<ahref=\"http://wenku.baidu.com/view/6889ebbc960590c69ec376a0.html\"target=\"_blank\">http://wenku.baidu.com/view/6889ebbc960590c69ec376a0.html</a>
上面网址的文库就是VC用ADO连接的Access,楼主可以参考一下,祝顺利。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行