LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using get properties VI from database toolkit

Hello I'm using database toolkit to read and import data from a MySql database.
 
I want to read the last row that has been written in a table. I don't know how to do this but i think i can know the number of the last row written using the get properties block.
 
But using this VI i have to use execute query block.....and i get an error, i think that the sql query is not defined correctly.
 
I have posted a part of my VI where i use this blocks.
 
I have two questions: is this the way to read the last row that has been written in  a table of a database??
 
The other question is why doesn't run this subVi and what is the correct way to define a SQL query (you have to put the table name, o some other thing)
 
Thank you very much
Larson
 
0 Kudos
Message 1 of 4
(2,855 Views)
Hi, Larson:

You can't read "the last row written" in a DataBase, as records are not sorted, by definition. You could have a field in a record that grows every time you insert in a table, like AutoNumeric, or DateTime and then you could know exactly wich record is the last one.

Once you know how to get "the last row written" you have to translate it to SQL. Provided you have an AutoNumeric field named "IdRow" in your table "TestTable", you could write:

SELECT * FROM TestTable WHERE IdRow = (MAX(t.IdRow) from TestTable t)

Now you should build a call to the DataBase.

First you need ExecuteQuery, as you did use, and SQL Query input should be the like "SELECT * FROM..."
Aitortxo.
0 Kudos
Message 2 of 4
(2,817 Views)
Hi, Larson:

You can't read "the last row written" in a DataBase, as records are not sorted, by definition. You could have a field in a record that grows every time you insert in a table, like AutoNumeric, or DateTime and then you could know exactly wich record is the last one.

Once you know how to get "the last row written" you have to translate it to SQL. Provided you have an AutoNumeric field named "IdRow" in your table "TestTable", you could write:

SELECT * FROM TestTable WHERE IdRow = (MAX(t.IdRow) from TestTable t)

Now you should build a call to the DataBase.

First you need ExecuteQuery, as you did use, and SQL Query input should be the like "SELECT * FROM..."
Aitortxo.
0 Kudos
Message 3 of 4
(2,817 Views)
I hate when this happens... if I press TAB + SPACE the message is sent to forum... :-s

-----------------------------
Hi, Larson:

You can't read "the last row written" in a DataBase, as records are not sorted, by definition. You could have a field in a record that grows every time you insert in a table, like AutoNumeric, or DateTime and then you could know exactly wich record is the last one.

Once you know how to get "the last row written" you have to translate it to SQL. Provided you have an AutoNumeric field named "IdRow" in your table "TestTable", you could write:

SELECT * FROM TestTable WHERE IdRow = (MAX(t.IdRow) from TestTable t)

Now you should build a call to the DataBase.

First you need ExecuteQuery, as you did use, and SQL Query input should be the like "SELECT * FROM..."

Second you have to retrieve the data with, for example, "DB Tools Fetch Recordset Data", in DB Palette, next to Execute Query. The output will be a Variant 2D Array that you can convert to anything you want, like String 2D Array, for example using Variant palette functions

And third you have to close the recordset Reference with "DB Tools Free Object", the rightmost function in the same row as Execute Query.

And once you have done all, you can close de DataBase.

Hope it helps,
Aitortxo.
0 Kudos
Message 4 of 4
(2,816 Views)