LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check to see if record exists in database

I am using Labview to generate random subject numbers, and enter them into an Access table provided that they do not already exist in the table. I have been trying to run a query from Labview but run into problems when the subject number does not exist, at which point the VI returns an error. Any thoughts? Thanks!
0 Kudos
Message 1 of 6
(4,194 Views)

You should be able to write SQL commands to query the dBase. Something along the lines of Select * Where Subject Number = xxxxxxx

 

You could then check the size of the array being returned to make sure it's > 0. 

 

Perhaps you could explain how you're connecitng to Access (which I have little experience with, I have used Microsoft SQL Server lots for similar tasks)

 

ActiveX I presume ?  Another options is to note the error returned when the number does not exist and clear that (but only that) error.

 

If you want to post any code I can see if I can help further.

 

Good luck

Chris R

Don't forget to give Kudo's for a good answer !

LabVIEW Champion
Certified LabVIEW Architect
Certified TestStand Architect
Message 2 of 6
(4,192 Views)
I am using the database toolkit. While trying to figure out how to do what you suggested, I found the "empty array?" function and tried that out. Here is a simplified version of what I want to do. It seems like it will work. Thanks for the advice! I am a beginner and need hints like this to help me along.
0 Kudos
Message 3 of 6
(4,185 Views)
0 Kudos
Message 4 of 6
(4,182 Views)

I will check that out when I get back in the office this evening and see if I can offer any more advice on what you're doing. I would check it right now but unfortunately I don't have 2010 on the laptop I am using at work. I have it at home so will check from there.

Don't forget to give Kudo's for a good answer !

LabVIEW Champion
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 5 of 6
(4,173 Views)

Jenny

Check out the atached code. One question I have for you is, Does the Fetch Recordset Data.vi throw an error if there is no matching data found (it looks like it should in the internal code but I have no way to test it) ?

 

If this is the case then the atached code should give you an idea how to deal with this.

 

I've also made a couple of small changes, maybe you're already aware that most of the controls that would be best suited to display database type records accept string data so I've given an example how to convert from variant data  (the data type returned by the database vi's)  to string data.

 

Hope this helps, any question please feel free to ask.

 

 

Don't forget to give Kudo's for a good answer !

LabVIEW Champion
Certified LabVIEW Architect
Certified TestStand Architect
Message 6 of 6
(4,157 Views)