LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get recordset from database

Hi all New to NI forums and only been Labviewing for a month. I wanted to get a record set from a database and spent ages searching for a way to do it with examples but could not find what I wanted, so after a couple of hours created my own and thought for the good of the community I would share it in the hope it will help someone else. It will return a Record set with the option to include the column names in the first row of a multidimensional string array created on the fly from the tables you wish to read.
A picture paints a thousand words, A video has thousands of pictures.
All help files should be viewed as video.
Download All
Message 1 of 9
(3,506 Views)

Hi Softman,

 

I would recommend that you post this code on the NI Developer Community as this may be useful for other developers.

 

Regards,

 

Christian Hartshorne

NI|UK

0 Kudos
Message 2 of 9
(3,475 Views)

Hi Christian

 

Thank you.

Now I know where to post, just posted it there.

A picture paints a thousand words, A video has thousands of pictures.
All help files should be viewed as video.
0 Kudos
Message 3 of 9
(3,465 Views)

If you use a Access database the Get property wont work if memory serves, and the double loop is overly complex, you only need the variant to string in the middle. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 9
(3,455 Views)

Hi

 

Thanks for your comments

I use MSSQL only but am interested in what you say, need examples to understand more.

A picture paints a thousand words, A video has thousands of pictures.
All help files should be viewed as video.
0 Kudos
Message 5 of 9
(3,452 Views)

Then i can tip you about Column named which includes spaces ... the default kit doesn't work and 'fixing' it to add '[' and ']' (as i did) isn't quite recommended as there's no SQL standard for such. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 9
(3,447 Views)

Er don't know what you mean, just tried my routine with spaces in column names and it worked fine

 

Columns with spaces.png

 

Top row is column names from the SQL database.

 

 

A picture paints a thousand words, A video has thousands of pictures.
All help files should be viewed as video.
0 Kudos
Message 7 of 9
(3,438 Views)

Does it also work if you do a Select with those column names? It might have been changed in later versions, but it caused me alot of head ache in 8.2 when it happened. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 9
(3,434 Views)

Well here is an interesting thing

 

The Select

SelectString.png

 

 

Causes an error here

 

Fault.png Error being Error.png

 

 

As you can see it can be trapped out, but still runs to produce the list

 

Result.png

 

But as you can see there is now a fault with the column names, as it has returned all the column names but I only wanted what was in the select

 

'SELECT [Primary Version],[Minor Version],TPname FROM TestPrograms'

 

I need to do a bit more work on how it returns only the columns you select, but it is working for the project I am doing so working on it again to fix the issue of selecting columns over return all ('Select * FROM TestProgram') will have to wait 😉

 

 

 

A picture paints a thousand words, A video has thousands of pictures.
All help files should be viewed as video.
0 Kudos
Message 9 of 9
(3,409 Views)