http://www.codeguru.com/Cpp/data/mfc_database/oledb/article.php/c1119/
#include <atldbcli.h>
#include <iostream>
using namespace std;
// define a class to hold the data from the table
class table_juso
{
public:
// data elements
int m_index;
TCHAR m_si[20];
TCHAR m_gu[20];
TCHAR m_dong[20];
// column binding — I only want these 4 fields
BEGIN_COLUMN_MAP(table_juso)
COLUMN_ENTRY(1, m_index)
COLUMN_ENTRY(2, m_si)
COLUMN_ENTRY(3, m_gu)
COLUMN_ENTRY(4, m_dong)
END_COLUMN_MAP()
};
// declare the OLEDB objects
CDataSource ds;
CSession session;
CCommand <CAccessor<table_juso> > cust;
int main()
{
try{
// fire up COM
HRESULT hr = CoInitialize(0);
if(FAILED(hr))
{
cout << “Can’t start COM!? ” << endl;
return -1;
}
// connect to the database
hr = ds.Open(_T(“MSDASQL”), “test”, “sa”, “password”);
if(FAILED(hr))
{
cout << “Can’t open test db” << endl;
return -1;
}
// start the session
hr = session.Open(ds);
if(FAILED(hr))
{
cout << “Can’t open test db SESSION” << endl;
ds.Close();
return -1;
}
// construct the query string
TCHAR mySQL[] = “exec p_juso_test1 100, 200″;
// open the dataset
hr = cust.Open(session, mySQL);
if(FAILED(hr))
{
cout << “Can’t open Nwind TABLE” << endl;
session.Close();
ds.Close();
return -1;
}
// read all the data
while(cust.MoveNext() == S_OK)
{
cout << cust.m_index << “, ” << cust.m_si << “, “;
cout << cust.m_gu << “, ” << cust.m_dong << endl;
}
cust.Close();
session.Close();
ds.Close();
cout << “That’s All Folks” << endl;
return 1;
}
catch(…)
{
cout << “Unknown failure” << endl;
return -1;
}
}