LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can not use the DBGetColChar (hstmt, 2, &str_arr,"") ?

I do not know why the command of DBGetColChar having the error. In my table Table1, column STRval (#2) Does any oneI have string values & I try to read them into str_val but it failed. Here are my codes:
 
char *str_val;
 
str_arr = calloc (100, sizeof(char));
 hstmt = DBActivateSQL (hdbc, "SELECT STRval FROM Table1"); 
 while (DBFetchNext (hstmt) != DB_EOF)
 {          
       DBGetColChar (hstmt, 2, &str_arr,"");         //   <---- ERROR
  
       InsertTextBoxLine (panelHandle, PANEL_TEXTBOX2, i , str_val);
      i++;    
 }
 
 DBDeactivateSQL(hstmt);
Does anyone know what is wrong? Thanks for any help
0 Kudos
Message 1 of 5
(3,521 Views)
Hi ATC_ATC,
 
What is the error message?  Does it fail the first time through the loop?  To make sure you do not call DBGetColChar when fetch failed, your while loop should be:
 
while ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

Also, you have to free str_arr in every iteration of the while loop:

DBFree (str_arr);

Best of luck!

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 2 of 5
(3,505 Views)
Hi David,
 
I found out my problem, since I search only 1 specific column, but I was looking for col2 (#2), instead of 1 ... it is Ok now. Thanks for help
 
*) But there is another problem with the   DBGetColChar (hstmt, 1, &str_val, "$");   ---> I try to retrieve currency into string, it shows only $56 instead of $56.78, do you know how to show it with 2 decimal point?
 
Thanks
0 Kudos
Message 3 of 5
(3,494 Views)
Hi ATC_ATC,
 
The CVI SQL Toolkit Reference Manual has instructions on this:  [CVI]\sql20\LabWindowsCVI SQL Ref Manual.pdf
 
The relevant part is: 

Format String:  $#,##0.00

Value: 

210.6

Formatted Value:  $210.60

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 4 of 5
(3,477 Views)

It works beautifully

Many thanks Smiley Happy

0 Kudos
Message 5 of 5
(3,470 Views)