Re: Database ODBC problem
Jonathan Blitz wrote:
returnValue = SQLBindCol(hstmt, 1, SQL_C_ULONG, &gamesData[0].gameId,
0,&gamesData[0].gameIdInd);
returnValue = SQLExecDirect(hstmt,(SQLWCHAR *)"SELECT game_id FROM
game",SQL_NTS);
What have I done wrong?
Jonathan Blitz
Shorter answer:
Microsoft's help gives a example of SQLBindCol :
#define NAME_LEN 50
#define PHONE_LEN 10
SQLCHAR szName[NAME_LEN], szPhone[PHONE_LEN];
SQLINTEGER sCustID, cbName, cbCustID, cbPhone;
SQLHSTMT hstmt;
SQLRETURN retcode;
retcode = SQLExecDirect(hstmt,
"SELECT CUSTID, NAME, PHONE FROM CUSTOMERS ORDER BY 2, 1, 3",
SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
/* Bind columns 1, 2, and 3 */
SQLBindCol(hstmt, 1, SQL_C_ULONG, &sCustID, 0, &cbCustID);
SQLBindCol(hstmt, 2, SQL_C_CHAR, szName, NAME_LEN, &cbName);
SQLBindCol(hstmt, 3, SQL_C_CHAR, szPhone, PHONE_LEN, &cbPhone);
/* Fetch and print each row of data. On */
/* an error, display a message and exit. */
while (TRUE) {
retcode = SQLFetch(hstmt);
if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
show_error();
}
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
fprintf(out, "%-*s %-5d %*s", NAME_LEN-1, szName,
sCustID, PHONE_LEN-1, szPhone);
} else {
break;
}
}
}
So, you should call SQLBindCol after SQLExecDirect, and use SQLFetch to
retrieve the data.
muchan