LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to compare value from database reading

Hi CVI Expert, 

 

I want to find if serial number that i input has already been exist on database or not. I use sql toolkit. My database is MS Access.

Here the code that i tried :

 

 

hdbc = DBConnect (connectString);
if (hdbc <= 0) {ShowError(); goto Error;}
hmap = DBBeginMap(hdbc);
if (hmap<=0) {ShowError(); goto Error;} 
resCode = DBMapColumnToChar (hmap, TraceSerial16, 17, uutNum, uutStat, "");
if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
hstmt = DBActivateMap(hmap,"CounterTable_Control");
if (hstmt==0)  {ShowError(); goto Error;}
while ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS) {
        
if (uutNum=="8003050013031014"){
statusSN = 1;
break;
}
else
statusSN = 0;
printf("Serial Number %s \n",uutNum);
}
if (statusSN==1){
MessagePopup("Status","OK");
resCode = DBDeactivateMap(hmap);
if ((resCode != DB_SUCCESS)) {ShowError(); goto Error;} 
resCode = DBDeactivateSQL (hstmt);
if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
resCode = DBDisconnect (hdbc);
if (resCode != DB_SUCCESS) {ShowError(); goto Error;}

 

 

My problem is, the comparison nevers succeed (red text). Can you help me why ?

 

Regards,

0 Kudos
Message 1 of 4
(3,167 Views)

Comparing strings works differently. You should use strcmp(string_1, string_2)

0 Kudos
Message 2 of 4
(3,165 Views)

Yeah, as Wolfgang said, use the ANSI C string compare library function.  Look at the help for the strcmp() function.  It returns 0 if the strings match.

 

In ANSI C,

 

if (uutNum=="8003050013031014")

 

acutally compares the pointers to the strings, not the string content.  That's why you never saw a match.

0 Kudos
Message 3 of 4
(3,156 Views)

Thank you guys. It works well.Smiley Happy

0 Kudos
Message 4 of 4
(3,152 Views)