This is a short sample of using ADO and ATL to connect to a SQLServer database
#include <iostream>
#include <fstream>
#include <string>
#include <ctype.h>
#include<atlbase.h>
#include<adoint.h>
using namespace std;
int main(int argc, char* argv[])
{
CoInitialize(0);
{
CComPtr<_Connection> pConn;
CComPtr<IUnknown> pUnk;
HRESULT hr=pConn.CoCreateInstance(L"ADODB.Connection",0,CLSCTX_INPROC_SERVER);
if(FAILED(hr))
{
cout<<"failed"<<endl;
}
hr=pConn->Open(SysAllocString(L"driver={SQL Server};server={ionf};uid={sa};pwd=mypwd;database=GENTRAN;"

,
SysAllocString(L"sa"

,SysAllocString(L"cereus"

,0);
if(FAILED(hr))
{
cout<<"failed"<<endl;
}
hr=pConn->Execute(SysAllocString(L"create table x
int,b char(1))"

,0,0,0);
if(FAILED(hr))
{
cout<<"failed"<<endl;
}
}
CoUninitialize();
return 0;
}
struct counter
{
char name[25];
short seats;
};
void tttmain()
{
ifstream inFile("dd.cpp"

;
return;
counter xxx;
if(inFile.fail())return;
while(!inFile.eof())
{
inFile.get(xxx.name, 25, '#');
inFile.ignore(1);
inFile >> xxx.seats;
inFile.ignore(100, '\n');
}
{
cout << endl << "Would you like to search for a name?";
cin >> xxx.name;
cin.ignore(100, '\n');
}
counter ddd[25];
char found=0;
short answer;
int total=0;
while(toupper(xxx.name[0]) == 'Y')
{
char newname[50];
cout << "Please enter a search name: ";
cin.getline(newname, 25);
for(short x = 0; x < 25; x++)
{
int numseats=0;
int total =0;
if(!strcmp(xxx.name,ddd[x].name))
{
numseats = ddd[x].seats;
total += numseats;
found = 'Y';
break;
}else
{
found = 'N';
}if(found == 'Y')
{
cout << "The name " << newname << " exists." << endl;
cout << "Would you like to enter another name?";
cin >> answer;
cin.ignore(100, '\n');
}
else
{
cout << "That name does not exist in the database." << endl;
cout << "Would you like to enter another name?";
cin >> xxx.name;
cin.ignore(100, '\n');
}
}
cout << "The total number of seats is: " << total << endl;
inFile.close();
}
if(0);
else
cout << "Error opening data file!" << endl;
}
John Fill
ivfmd@mail.md