Skip to content

Instantly share code, notes, and snippets.

@cx20
Created June 10, 2012 14:15
Show Gist options
  • Save cx20/2905846 to your computer and use it in GitHub Desktop.
Save cx20/2905846 to your computer and use it in GitHub Desktop.
Hello, ODBC(MFC) World!
#include <afx.h>
#include <afxdb.h>
int _tmain( int argc, TCHAR* argv[] )
{
CDatabase db;
CString strCon = _T("Driver={SQL Server};SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd");
CString strSQL = _T("SELECT 'Hello, ODBC(MFC) World!' AS Message");
db.OpenEx( strCon );
CRecordset rs( &db );
rs.Open( CRecordset::forwardOnly, strSQL );
CString strMessage;
while( !rs.IsEOF() )
{
rs.GetFieldValue( (short)0, strMessage );
_tprintf( _T("%s\n"), (LPCTSTR)strMessage );
rs.MoveNext();
}
rs.Close();
db.Close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment