NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
JennyT
Posts: 8
0 Kudos
Accepted Solution

How to programmatically retrieve a single record from Access?

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!
Knight of NI
Dennis_Knutson
Posts: 29,306

Re: How to programmatically retrieve a single record from Access?

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

Active Participant
jcarmody
Posts: 1,561
0 Kudos

Re: How to programmatically retrieve a single record from Access?

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
CLD
Active Participant
josborne
Posts: 605
0 Kudos

Re: How to programmatically retrieve a single record from Access?

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'

Trusted Enthusiast
falkpl
Posts: 2,291
0 Kudos

Re: How to programmatically retrieve a single record from Access?

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.
CLD, CPI
Labview 4.0- 2011, RT, Vision, FPGA
Active Participant
jcarmody
Posts: 1,561
0 Kudos

Re: How to programmatically retrieve a single record from Access?


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
CLD
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page