Example Code

Easy read and write to database

Code and Documents

Attachment

Download All

Summary:

-This VIs reads and writes data to database table true Labview cluster.

The benefit of this code is that you only update/create cluster and database table and you have a full functional code for read/write your data to database.

Function:

The DB_Read use the cluster to define the table and column in your database and pass the result into the array returned data depending on your SQL query.

The DB_Write  writes the data in your cluster do the database and read back its record key.

Steps to execute code:

  1. Create a desired table in your database and define your data types.
  2. Open DB_Read example and modify the table cluster. Start by name the cluster equal to table name in the database and then create controls for each column in the table with equal names and data types. Replace this cluster with the one inside the array (result array cluster).Save this VI as desired name for this operation (Tablename_Read.vi)
  3. Open DB_Write example select the table cluster and paste in the cluster made in step 2. If you have set a primary key with auto indexing this column must be deleted from the cluster. Edit the query in the block diagram to fit your new table with your new column name. Save this VI as desired name for this operation (Tablename_Write.vi)
  4. Just read and write your data to your database by using your new VIs

Screenshots:

DB_Read.jpg

DB_Write.jpg

VI Snippet:

DB_Read_D.jpg

DB_Write_D.jpg

VI attached below

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

Comments
TrondEnger
Member
Member
on

Clever solution!

M.Nou
Member
Member
on

I have found this error  Error -2147467259 occurred at NI_Database_API.lvlib:Cmd Execute.vi->NI_Database_API.lvlib:DB Tools Insert Data.vi->Untitled 1

please i need help

Contributors