1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <tchar.h>
#define MAX_DATA 100
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
RETCODE rc; /* Return code for ODBC functions */
HENV henv; /* Environment handle */
HDBC hdbc; /* Connection handle */
HSTMT hstmt; /* Statement handle */
char szData[MAX_DATA]; /* Variable to hold data retrieved */
SDWORD cbData; /* Output length of data */
SQLAllocEnv(&henv);
SQLAllocConnect(henv, &hdbc);
SQLConnect(hdbc, _T("hello"), SQL_NTS, NULL, 0, NULL, 0); // "hello" refers to the DSN
SQLAllocStmt(hdbc, &hstmt); // or Data Source Name
SQLExecDirect(hstmt, _T("SELECT * FROM hello.txt"), SQL_NTS);
rc = SQLFetch(hstmt);
while (rc == SQL_SUCCESS) {
SQLGetData(hstmt, 1, SQL_C_CHAR, szData, sizeof(szData), &cbData);
MessageBoxA(NULL, szData, "ODBC", MB_OK);
rc = SQLFetch(hstmt);
}
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return(TRUE);
}
|