Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
4 ratings:
 3.75 out of 5   

How Can I Over-Write an Existing Value in a Database Table from LabVIEW?



Primary Software:
Primary Software Version: 1.0.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I am using the Database Connectivity Toolset in LabVIEW to manipulate data in a Database. I want to update a single value in my database table, but the DB Tools Insert Data VI seems to only insert new data. How can I update an existing cell value?

Solution:
Appendix A of the Database Connectivity Toolset User Manual  briefly lists and explains the use of common SQL commands, operators, and functions available for databases. One of the available commands is UPDATE. UPDATE is used to set columns in existing rows to new values. To run a Query using the Database Connectivity Toolset VIs, you will use the DB Tools Execute Query and DB Tools Free Object VIs from the Advanced Sub-Palette of the Database Connectivity Toolset Palette. See the attached SQLQuery image for how to use them.

The format of the UPDATE query is:

UPDATE table_name SET column_name = new_value WHERE column_name = value

For example,

UPDATE Table1 SET Value = 12 WHERE Value = 10

Note that every place in the column named Value with a value of 10 will be changed to 12. To limit the update by adding more qualifications, the format is:

UPDATE table_name SET column_name = new_value WHERE column_name = value AND column_name = value

For example,

UPDATE Table1 SET Value = 12 WHERE Value = 10 AND USERID = 14

You can add more qualifications by using the AND statement repeatedly. To update a non-numeric entry, the values will have to be surrounded by a single quote. For example,

UPDATE Table1 SET Name = 'Test' WHERE USERID = 0 AND Value = 12

Related Links:
Product Manuals: Database Connectivity Toolset User Manual


Attachments:


SQLQuery.GIF


Report Date: 11/17/2003
Last Updated: 02/08/2010
Document ID: 33GD8L59

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit