// ADOsample.cpp : Defines the entry point for the console application. // #include "stdafx.h" #import "D:\Program Files\Common Files\System\ADO\msado21.tlb" \ no_namespace rename("EOF", "EndOfFile") int main(int argc, char* argv[]) { _RecordsetPtr rs; _ConnectionPtr conn; CoInitialize(0); try { HRESULT hr = conn.CreateInstance( __uuidof(Connection) ); if (FAILED(hr)) _com_issue_error(hr); conn->Open( L"Provider=VFPOLEDB.1;" L"Data Source=D:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc;Collating Sequence=MACHINE", "", "", -1 ); rs = conn->Execute( L"Select company, contact from customer", &vtMissing, adOptionUnspecified); while( !rs->EndOfFile ) { printf("%s %s\n", (char*)_bstr_t(rs->Fields->Item[0L]->Value), (char*)_bstr_t(rs->Fields->Item[1L]->Value)); rs->MoveNext(); } rs->Close(); conn->Close(); } catch( _com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bs = _bstr_t("Error: ") + _bstr_t(e.Error()) + _bstr_t("\nMsg: ") + _bstr_t(e.ErrorMessage()) + _bstr_t("\nDescription: ") + _bstr_t(e.Description()); MessageBox(0, bs, bstrSource, MB_OK); } CoUninitialize(); return 0; }You could also check AdoClass from www.codeproject.com, which can simplify the code writing.