I'm trying to make a program that connects to a database and then gets the information from it...
But I'm having a problem, it compiles very well, but I get this "error", when I try to rum the program:
Code:
CreateInstance result=0 uuidof=1300
Connection object created.
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
This is the code of my program:
Code:
#include <stdio.h>
#include "E:\Program Files\Microsoft Visual Studio\VC98\mfc\SRC\stdafx.h"
#import "c:\program files\common files\system\ado\msado15.dll" rename("EOF", "EOFile")
struct StartOLEProcess {
StartOLEProcess() {
::CoInitialize(NULL);
}
~StartOLEProcess() {
::CoUninitialize();
}
} _start_StartOLEProcess;
int main() {
ADODB::_ConnectionPtr Con = NULL;
ADODB::_RecordsetPtr RecSet = NULL;
ADODB::FieldPtr pQuestions;
_variant_t vQuestions;
char sQuestions[150];
HRESULT hr = S_OK;
VARIANT *RecordsAffected = NULL;
hr = Con.CreateInstance(__uuidof(ADODB::Connection));
printf("\nCreateInstance result=%d uuidof=%d\n", hr, __uuidof(ADODB::Connection));
printf("\nConnection object created.");
Con->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\database.mdb", "", "", 0);
printf("\nConnection opened...");
RecSet = Con->Execute("SELECT * FROM quiz", RecordsAffected, 1);
printf("\nSQL statement processed");
char File[10] = "Questions";
pQuestions = RecSet->Fields->GetItem(File);
printf("\nGetting data now...\n");
while(!RecSet->EOFile) {
vQuestions.Clear();
vQuestions = pQuestions->Value;
WideCharToMultiByte(CP_ACP, 0, vQuestions.bstrVal, -1, sQuestions, sizeof(sQuestions), NULL, NULL);
printf("\n%s", sQuestions);
RecSet->MoveNext();
}
printf("\n\nEnd of data..");
RecSet->Close();
RecSet = NULL;
printf("\nClosed and removed recordset object.");
Con->Close();
Con = NULL;
printf("\nClosed and removed connection object.");
return 0;
}
Will somebody please help me out here...
Thx in advance...