LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading simple data from a database (Database Connectivity Toolkit)

Solved!
Go to solution

Hi everyone !

 

I'm posting here because I'm really stuck at this moment on a apparently very simple matter.
I'm establishing a connection with a database, and writing data in a table, this table has 4 columns.

After writing some random data, I'm displaying those by using the "Select Data" VI, and it works great, unless I'm dealing with Decimal(20,0) datatypes..

I have really no idea from where it could come from.

 

I tried modifying the input type (as strings for example) before bundling the cluster of data being sent to the database, without any result.

Maybe there's a trick I'm missing here !

 

Thank you for your help !

Unbenannt.jpg

0 Kudos
Message 1 of 7
(4,041 Views)

Hey,

could you provide your VI to better understand the issue.

Did you test to read decimal data manually written to the database to varify it's a reading and not a writing error?

0 Kudos
Message 2 of 7
(4,000 Views)

Hi ! Thanks for your reply !

 

By using the "Database Variant To Data Function" ( http://zone.ni.com/reference/en-XX/help/370016E-01/lvdatabase/database_variant_to_data/ )from the database toolkit, I actually managed to display my data correctly. (see next picture)

VI.jpg

VI2.jpg

 

The problem looks like to be in the output data from my database which is given to me after using the SELECT function.. I have to convert it to make my numbers (the first two item of the sent cluster)  displayable (but the date and the varchar can be directly displayed)

I could upload the VI but I need to remove some sensitive data first ^^.

But still, it looks like the data were correctly written since they're displayable after this "Variant To Data Function"..

 

Now I'm just wondering if I could skip this step or if it's definetly necessary !

 

And by the way, the first two columns in my database table are DECIMAL(20,0), so I first tried to send them as simple integers (on labview) in my cluster.. like this

earset.jpg

 

but it didn't change anything..

0 Kudos
Message 3 of 7
(3,996 Views)

http://home.hit.no/~hansha/documents/software/documents/DCT_User_Manual.pdf

 

Page 32 shows exactly what I'm trying to do.. and it seems to work in their example.

Hmmm

0 Kudos
Message 4 of 7
(3,983 Views)

I just tested it with an .mdl database and it worked. Could you provide some minimal example code with a small database that I can check your issue.

0 Kudos
Message 5 of 7
(3,956 Views)
Solution
Accepted by Soulstorm

I often use a typdef cluster to define the data inserted or selected from a database.

 

Some time ago, I created a VI that uses a scripting function to read the structure of a table and create a cluster.

 

Run this, save the resulting cluster as a typedef, then use it as the prototype to the "Database Variant to Data" function.

 

If you change your database table structure, you would need to update/replace the typedef.

 

https://forums.ni.com/t5/LabVIEW-APIs-Documents/DB-Tools-Create-Cluster-from-Table-vi/ta-p/3516670

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 6 of 7
(3,949 Views)

That's a great solution !

 

However, converting the data with "Database Variant to Data" from the DB Toolkit solved my issue.. considering the relative small size of my database, that should do the trick.

 

I'll keep your solution in mind nonetheless, it could be useful in the future !

 

0 Kudos
Message 7 of 7
(3,938 Views)