#include<stdio.h>
#include"C:\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;
void main(void)
{
ADODB::_ConnectionPtr con = NULL;
ADODB::_RecordsetPtr rec = NULL;
ADODB::FieldPtr pAuthor;
_variant_t vAuthor;
char sAuthor[40];
HRESULT hr = S_OK;
char File[255], ConStr[500];
VARIANT *vRecordsAffected = NULL;
int ctr;
printf("\nEnter Database Path and File name: ");
fgets(File, 250, stdin);
for (ctr = 0; (unsigned int)ctr < strlen(File); ctr++)
{
if (File[ctr] == '\n')
{
File[ctr] = '\0';
break;
}
}
ConStr[0] = '\0';
strcat(ConStr, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=");
strcat(ConStr, File);
hr = con.CreateInstance(__uuidof(ADODB::Connection));
printf("\nCreateInstance result= %d uuidof= %d\n", hr, __uuidof(ADODB::Connection));
printf("\nConnection object created.");
con->Open(ConStr, "", "", 0);
printf("\nConnection opened.");
printf("\nEnter Database table name: ");
fgets(File, 250, stdin);
for (ctr = 0; (unsigned int)ctr < strlen(File); ctr++)
{
if (File[ctr] == '\n')
{
File[ctr] = '\0';
break;
}
}
ConStr[0] = '\0';
strcat(ConStr, "SELECT * FROM ");
strcat(ConStr, File);
rec = con->Execute(ConStr, vRecordsAffected, 1);
printf("\nSQL statement processed");
printf("\nEnter Database field name: ");
fgets(File, 250, stdin);
for (ctr = 0; (unsigned int)ctr < strlen(File); ctr++)
{
if (File[ctr] == '\n')
{
File[ctr] = '\0';
break;
}
}
pAuthor = rec->Fields->GetItem(File);
if ((pAuthor->Type == 202)||(pAuthor->Type == 203))
{
printf("\nGetting data now...\n");
while (!rec->EOFile)
{
vAuthor.Clear();
vAuthor = pAuthor->Value;
WideCharToMultiByte(CP_ACP, 0, vAuthor.bstrVal, -1, sAuthor, sizeof(sAuthor), NULL, NULL);
printf("\n%s", sAuthor);
rec->MoveNext();
}
printf("\n\nEnd of data.");
}
else
{
if ((pAuthor->Type == 11)||(pAuthor->Type == 7))
{
printf("\nGetting data now...\n");
while (!rec->EOFile)
{
vAuthor.Clear();
vAuthor = pAuthor->Value;
printf("\n%d", vAuthor.boolVal);
rec->MoveNext();
}
printf("\n\nEnd of data.");
}
else
{
if (pAuthor->Type == 2)
{
printf("\nGetting data now...\n");
while (!rec->EOFile)
{
vAuthor.Clear();
vAuthor = pAuthor->Value;
printf("\n%d", vAuthor.intVal);
rec->MoveNext();
}
printf("\n\nEnd of data.");
}
else
{
printf("\nUnable to handle that data type, %d", pAuthor->Type);
}
}
}
rec->Close();
rec = NULL;
printf("\nClosed and removed recordset object.");
con->Close();
con = NULL;
printf("\nClosed and removed connection object.");
return;
}