LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DBActivateSQL

Solved!
Go to solution

I have a table that looks like this

 

Item_number    Active  Test Specifications ....

1111                     0            

2222                     1

3333                     1

4444                     1

 

If I run after opening the database.

 

iTableHandle = DBActivateSQL(iDatabaseHandle, "SELECT * FROM tblTest WHERE Active = 1 AND ItemNumber = '5555'");

 

DBActivateSQL returns a 3 same value if I replaced 5555 with 4444.

 

Shouldn't DBActivateSQL return an error since it did not find anything?  I want to fail if the user enters the wrong itemnumber or one that is inactive.

0 Kudos
Message 1 of 3
(3,369 Views)
Solution

Paul,

 

I don't think the function should give an error, it's just not finding anything.  It would give an error if your SQL statement was malformed or if you were trying to access a column that doesn't exist, but not if your WHERE clause returns no values.   You'd need to set up your DBBinds, then call DBFetchNext.  You could have some logic in your code to display an error if the first call to DBFetchNext didn't return 0 (indicating no records were found) and then allow your user to enter a different number.

Eric B.
National Instruments
0 Kudos
Message 2 of 3
(3,352 Views)

You can use this:

 

DBActivateSQL(iDatabaseHandle, "SELECT * FROM tblTest WHERE Active = 1 AND ItemNumber = '5555'");

if (DBNumberOfRecords (iTableHandle )==0)

    MessagePopup("SQL Error","No records found");

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