Database Connectivity using ADO
I want to connect my application written in VC++ version 6 .....to a MS Access Database using ADO .....i have attached the source code below ......it is compiling and linking properly but there is no output for some strange reasons ....i have made the logical connection of the database from the System DSN in Control Panel and have successfully tested it ..... but nothing is happening .....i have used the Sample 'Northwind.mdb' database present in MS Access and placed it on the root of C Drive and the connection string is 'xxx' ......so could some1 check my code and point out my errors .......thanx in advance
// xyz.cpp : Defines the entry point for the application. //
#include 'stdafx.h' #include #include #include
#import 'c:\Program Files\Common Files\System\ADO\msado15.dll' \ no_namespace rename('EOF', 'EndOfFile')
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
//int main(void) { CoInitialize(NULL); try
{ _RecordsetPtr pRst('ADODB.Recordset'); // Connection String _bstr_t strCnn('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;DBQ=Northwind.mdb'); // Open table pRst->Open('SELECT Customer FROM Orders*;', strCnn, adOpenStatic, adLockReadOnly, adCmdText);
pRst->MoveFirst();
while (!pRst->EndOfFile) { cout<<(char*) ((_bstr_t) pRst->GetFields()->GetItem('xxx')->GetValue())<MoveNext(); } pRst->Close();
} catch (_com_error &e)
{ cout<<(char*) e.Description(); getch(); } ::CoUninitialize();
return 0; }