2个回答
展开全部
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents and Settings\\List.mdb;Persist Security Info=False";
pConn->Open("","","",adConnectUnspecified);
MessageBox("数据库连接正常!");
pRst=pConn->Execute("select * from DB1",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("列名"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents and Settings\\List.mdb;Persist Security Info=False";
pConn->Open("","","",adConnectUnspecified);
MessageBox("数据库连接正常!");
pRst=pConn->Execute("select * from DB1",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("列名"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
追问
写在哪个文件下?
追答
在你响应查询数据库的事件的源文件中去写。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询