LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL INSERT INTO

Hello,

 

Is it possible to get feedback that INSERT INTO was successfully executed?

 

regards

Niklasson

 

 

0 Kudos
Message 1 of 5
(2,555 Views)

Since this is a LabVIEW forum, I assume you are talking about using the Database Connectivity Toolkit.  All VI's in the toolkit should have an Error Out terminal that will alert you if the query failed.  You can use transactions, although that seems a bit overkill for a simple insert query. 

 

If you need more specific answers, ask a specific'er question. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 5
(2,517 Views)

Agreed, the error out will tell you if it failed, so that's your indirect way of knowing it was a success.

 

Could also build a follow-up query that pulls the record you just updated and validates it's correct. Overkill? Depends on your application I suppose.

0 Kudos
Message 3 of 5
(2,480 Views)

"Could also build a follow-up query that pulls the record you just updated and validates it's correct"

 

This will only work if no one else is writing to the database table.  Multiple writers (say 3 versions of the same test machines) could result in reading back the wrong record.

 

You'll want to go with a stored procedure with a defined output parameter.

0 Kudos
Message 4 of 5
(2,471 Views)

@pjroland1121 wrote:

"Could also build a follow-up query that pulls the record you just updated and validates it's correct"

 

This will only work if no one else is writing to the database table.  Multiple writers (say 3 versions of the same test machines) could result in reading back the wrong record.

 

You'll want to go with a stored procedure with a defined output parameter.


To add to this, if you are inserting into a table with an identity specification, you can query this value as your output parameter.  If the insert was not successful, you should get a NULL value, depending on the method used.  You can do your own research to see which one fits your scenario best.  

  • scope_identity() - I think this is the preferred method when called from a stored procedure because it is only applicable to that session and the same scope (within the stored procedure).  
  • @@identity - Returns identity of last session.
  • ident_current(name) - returns last identity for a specific table from any session.  
aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 5
(2,464 Views)