Created
June 10, 2012 14:21
-
-
Save cx20/2905884 to your computer and use it in GitHub Desktop.
Hello, ADO(C++) World! (ADO + OLEDB + SQL Server)
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 <stdio.h> | |
#include <tchar.h> | |
#import "msado15.dll" no_namespace rename("EOF", "adoEOF") | |
int _tmain( int argc, TCHAR* argv[] ) | |
{ | |
CoInitialize(NULL); | |
_ConnectionPtr cn("ADODB.Connection"); | |
_RecordsetPtr rs("ADODB.Recordset"); | |
cn->Open( _T("PROVIDER=SQLOLEDB;SERVER=(local);DATABASE=master;"), | |
_T("sa"), _T("P@ssW0rd"), adConnectUnspecified), | |
rs = cn->Execute( _T("SELECT 'Hello, ADO(C++) World' AS Message"), NULL, adCmdText ); | |
while ( !rs->EndOfFile ) | |
{ | |
_variant_t var = rs->Fields->GetItem( 0L )->Value; | |
_tprintf( _T("%s\n"), (LPCTSTR)(_bstr_t)var ); | |
rs->MoveNext(); | |
} | |
rs->Close(); | |
cn->Close(); | |
rs = NULL; | |
cn = NULL; | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment