Created
June 10, 2012 14:17
-
-
Save cx20/2905868 to your computer and use it in GitHub Desktop.
Hello, OLE DB(C++) World!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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