
CoInitialize(NULL);
_ConnectionPtr Conn(__uuidof(Connection)); // 初始化一个链接
Conn->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\db.mdb";
Conn->Open("","","",adModeUnknown);
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr cmd(__uuidof(Command));
cmd->put_ActiveConnection(_variant_t((IDispatch*)Conn));
cmd->CommandText = "SELECT * FROM [test] where id=28";
pRst = cmd->Execute(NULL,NULL,adCmdText);
CString msg = "";
while(!pRst->rsEOF)
{
msg += (_bstr_t)pRst->GetCollect("字段名称");
pRst->MoveNext();
}
pRst->Close();
Conn->Close();
cmd.Release();
pRst.Release();
Conn.Release();
CoUninitialize();
char *message = msg.GetBuffer(msg.GetLength()+1);
SetDlgItemText(IDC_EDIT2,message);
最后不要忘记引用 MS ADO的DLL文件
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")