Skip to content

Instantly share code, notes, and snippets.

@cx20
Created June 10, 2012 14:17
Show Gist options
  • Save cx20/2905868 to your computer and use it in GitHub Desktop.
Save cx20/2905868 to your computer and use it in GitHub Desktop.
Hello, OLE DB(C++) World!
#include <atldbcli.h>
int _tmain( int argc, TCHAR* argv[] )
{
CoInitialize(NULL);
USES_CONVERSION;
CDataSource ds;
CSession ses;
CCommand<CDynamicAccessor> rs;
WCHAR szCon[] = L"PROVIDER=SQLOLEDB;SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd";
WCHAR szSQL[] = L"SELECT 'Hello, OLE DB World!' AS Message";
ds.OpenFromInitializationString( szCon );
ses.Open( ds );
rs.Open( ses, szSQL );
while( rs.MoveNext() == S_OK )
{
_tprintf( _T("%s\n"), OLE2T( rs.GetColumnName(1) ) );
_tprintf( _T("--------------------\n") );
_tprintf( _T("%s\n"), (LPCTSTR)rs.GetValue(1) );
}
ses.Close();
ds.Close();
CoInitialize(NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment