12-03-2018 03:33 PM
Hi,
I'm currently programming a SQL statement with DBBindCol... I'm getting either ASCI characters out or garbage characters. I'm wondering if there anything special I need to do to make sure it reads the right variable I selected in the statement. Are the two pointers just to show the address of the variable I selected. If so, what does DBFetchNext(hstmt) do? I get an error everytime I run it. Thanks!
Below is a sample of what I'm trying to do:
hstmt = DBActivateSQL(hdbc, "SELECT TESTINDEX,SESSIONID,OPERATOR,SN,TESTDATE,TEST_TIME,ERRNUM,ERRDES,SYSNUM FROM REG_RESULTSTABLE WHERE SN = 260887");
if(hstmt <= 0)
{
ShowError();
}
int nrec = 0;
nrec = DBNumberOfRecords(hstmt);
if(nrec<=0)
{
ShowError(); /*goto Error;*/
}
resCode = DBBindColInt(hstmt,1,&Test_Index,&T_Index);
if(resCode != DB_SUCCESS)
{
ShowError(); /*goto Error;*/
}
while((resCode = DBFetchNext(hstmt)) == DB_SUCCESS)
{
sprintf(TI,"%d \t\t\t",Test_Index);
SetCtrlVal(panelHandle,PANEL_lstregulator,TI);
}
Solved! Go to Solution.
12-04-2018 05:20 AM
The first pointer in DBBindColInt function (the same as other binding functions) is the address of the variable where to put the value read from the database, the second one offers a detail about the status of the value itself (whether normal, truncated or null). After running the SQL statement, DBFetch will read the first / next record extracted putting the values in the variables bound to each column.
What error are you receiving? You may have problems in the sql if SN column is a string instead of the number, since in that case you must enclose the value in single quotes.
12-04-2018 12:36 PM
Okay, I see. I was getting some errors but now I think its the way my code is written that is throwing errors at me.