LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to UPDATE if records exists Else enter new record using DB toolkit.

Create a recod and Update a record is not problem. It works but i want to update if records exists else create a new record. is this possible using DB tool.?

0 Kudos
Message 1 of 8
(4,958 Views)

It is, using a custom SQL query - it depends on what database you are using (e.g. MSSQL/MySQL) - I'm sure if you google "insert or update query" you will find lots of answers - it's probably possible in most database engines.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 8
(4,948 Views)

Thanks for your reply. I am using MS Access and DB toolkit from Labview..

0 Kudos
Message 3 of 8
(4,935 Views)

The DB toolkit can execute any SQL query(ies) on your database. You just need to find out the appropriate query in MS Access. If there isn't a built in option in MS Access databases (in MySQL there is a DUPLICATE KEY option which allows you to insert/update in one query), you can always do a SELECT statement to see if the record exists and then either INSERT or UPDATE in the second query.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 8
(4,931 Views)
Since updating typically happens far more often than inserting, I will first do an update. One of the outputs of an SQL run function is a count of the number of records that were modified. If this value is 0, I repeat but do an insert instead.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 8
(4,899 Views)

Thanks for ur reply. I understood your points.  I did the same logic(select query and check the records and if it s not there create new record) but would like to use in single logic. It will be available in other programming.

0 Kudos
Message 6 of 8
(4,881 Views)
Then you need to do the recommended search for the syntax. This is not a LabVIEW question. If you know it's available in other programming languages, what is the problem? The SQL syntax is not different.
0 Kudos
Message 7 of 8
(4,867 Views)

I understand this post is old, and this is my first post. However, I'd like to share a solution that I created for my particular application.

 

Program Background

I have configuration files (aka files that have the performance tolerances) that I want to upload to a database (viewed from MS Access). I want to check if the user specified configuration already exists in the database. If it doesn't exist, the configuration is inserted into the respective table. If it does, then ask the user if they want to update the database.

 

Solution
1. This code is a portion of a much larger program that creates a test database, but I've isolated this portion to share with whoever may find this helpful.
2. Everything is in the attached .zip.
3. This is my first time working with Labview, so if you see something that makes you go "what the hell is he doing?", please let me know 🙂

4. Default system directory is user desktop.  Please keep everything in the folder together, or you will need to update links, etc.

5. When the table is updated, I update every column in the table because that's what I wanted for this particular application.

0 Kudos
Message 8 of 8
(3,676 Views)