Example Code

DB Toolkit Execute Query on Steroids in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW Database Connectivity Toolkit
  • LabVIEW

Code and Documents

Attachment

Description

1. Overview

The National Instruments DBToolkit provides VI’s for opening database connections, executing queries and parameterized queries, listing table properties, and navigating the resultant recordset(s) returned from a query. This simple VI wraps a number of calls to functions in the DBToolkit to provide a fully-functional and handy wrapper to execute queries against a database and return results.

 

2. Description

The code makes a database connection, executes a standard or prameterized query, enumerates the resultant recordsets and column names, and returns an array of column name / recordset data. The VI also provides convenience outputs for the first recordset found in the query – most of the time a single recordset is returned.

 

3. Requirements

  • NI LabVIEW Professional Development System 2012 or compatible.
  • NI Database Connectivity Toolkit 2012 or compatible.

 

4. Steps to Implement or Execute Code

  1. You must have the NI DBToolkit installed to use this code.
  2. Drop a copy of the VI on your block diagram.
  3. Provide a connection string input, OR, set “Use connection dialog” = true to use the built-in DBToolkit browse to database function.
  4. Provide a query string input.
  5. If you are executing a parameterized query, populate the array of stored procedure parameters. Note: leave this array empty if you are simply executing a query string.
  6. The VI will connect to the database, execute the query, and enumerate resultant recordsets.
    Inspect the returned query results and enjoy!

 

5. Additional Information or References

DBT - Execute Query LabVIEW 2012 NIVerified.png

 

 

**The code for this example has been edited to meet the new Community Example Style Guidelines.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.