LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically retrieve a single record from Access?

Solved!
Go to solution
I need to retrieve a single record from Access. I have two columns, "Sess" and "Subject" in my database. I want to retrieve the Session number ("Sess") for a particular subject and display it on the front panel. I have made up the attached VI based on an example I found. This VI displays the Session number for the first record, but I can't figure out how to designate a search for a specific record in the table.  Thanks!
0 Kudos
Message 1 of 6
(2,859 Views)
Solution
Accepted by JennyT

Do a google search for 'sql tutorial'. You need to learn how the SELECT statement works. The general syntax is:

 

SELECT column_name(s)
FROM table_name
WHERE column_name operator value

Message 2 of 6
(2,845 Views)

I fetch all the recordset data and work on the array, rather than iterating through the recordset.  Like this:

 

Retrieve%20record[1]_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 6
(2,839 Views)

Retrieving all the records and then iterating through them is extremely inefficient.  What if you have millions of records?

 

Just use this SQL statement:

 

SELECT Sess FROM yourtablename WHERE Subject = 'blahblahblah'

http://www.medicollector.com
0 Kudos
Message 4 of 6
(2,831 Views)

Also consider adding the LIMIT clause to set the max number of records to 1 (add LIMIT 1 to end of sql statement)

if the querry is not known to be unique.  You can also sork prior to limit to get things like most recent or first or lest based on some other criteria.

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 5 of 6
(2,825 Views)

@josborne wrote:

Retrieving all the records and then iterating through them is extremely inefficient.  What if you have millions of records?

 

Just use this SQL statement:

 

SELECT Sess FROM yourtablename WHERE Subject = 'blahblahblah'


Not sure if this was directed at my comment, but...  I didn't say retrieve all records, I said fetch the recordset data.  The recordset contains the records that match the query (which, in my snippet, looks much like your SQL statement).  You have another problem if your query can return millions of records but you only want one.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 6 of 6
(2,818 Views)