LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with DBBindCol function

Solved!
Go to solution

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);

}

0 Kudos
Message 1 of 3
(1,901 Views)
Solution
Accepted by topic author mpwbs

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(1,878 Views)

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.

0 Kudos
Message 3 of 3
(1,867 Views)