ODBC不从表返回值

时间:2015-04-09 07:53:59

标签: sqlbindparameter

我无法通过ododc获得正确的值。 odbc返回值-858993460,而不是将存储在表中的值返回到变量rezervovani。我怀疑在sqlbindparameter中使用了错误的数据类型,但我不知道在哪里。

DSN连接字符串将从错误报告中删除。 请给出建议。

    int _tmain(int argc, _TCHAR* argv[])
{

SQLHENV hEnv; 
SQLRETURN ret;u
SQLHDBC hDB2dbc; 
SQLHSTMT hDB2stm; 

SQLINTEGER rezervovani, nts = SQL_NTS; 

string stm = "select"
" (select count(*) from bk_klienti_report where stav = 1) rezervovany,"
" (select count(*) from bk_klienti_report where stav = 2) konfigurace,"
" (select count(*) from bk_klienti_report where funkcni = 1) funkcni,"
" (select sum(zruseny) from bk_klienti_report where stav = 3) zruseny,"
" (select sum(nova_smlouva_dodatek) from bk_klienti_report) dodatek,"
" (select sum(funkcni) from bk_klienti_report where majitel = 'Podnikatel') podnikatel,"
" (select sum(funkcni) from bk_klienti_report where majitel = 'Obcan') obcan,"
" (select sum(funkcni) from bk_klienti_report where majitel = 'Zamestnanec') zamestnanec,"
" (select sum(disp_fo) from bk_klienti_report where funkcni = 1) + (select sum(disp_fo) from bk_klienti_report where pouze_smlouva = 1) disponenti_fo,"
" (select sum(disp_po) from bk_klienti_report where funkcni = 1) + (select sum(disp_po) from bk_klienti_report where pouze_smlouva = 1) disponenti_po"
" from bkdat001.bk_klienti_report";

ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);

ret = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_UINTEGER);


ret = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDB2dbc);

ret = SQLConnectA(hDB2dbc, (SQLCHAR*)DB2DSN.c_str(), DB2DSN.length(), (SQLCHAR*)DB2USR.c_str(), DB2USR.length(), (SQLCHAR*)DB2PWD.c_str(), DB2PWD.length());


ret = SQLAllocHandle(SQL_HANDLE_STMT, hDB2dbc, &hDB2stm);


ret = SQLPrepareA(hDB2stm, (SQLCHAR *)stm.c_str(), SQL_NTS);

ret = SQLBindParameter(hDB2stm, 3, SQL_PARAM_INPUT, SQL_C_SSHORT,  SQL_INTEGER, NULL, 0, &rezervovani, sizeof(rezervovani), (SQLINTEGER *)nts);


ret = SQLExecute(hDB2stm);


cout << rezervovani


SQLDisconnect(hDB2dbc);
SQLFreeHandle(SQL_HANDLE_DBC, hEnv);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

return 1;

}

0 个答案:

没有答案