Quizzes & Puzzles38 mins ago
Database Connectivity using ADO
1 Answers
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; }
Answers
Best Answer
No best answer has yet been selected by mufazzal. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.