LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help Needed!! Working with SQL Databases

Solved!
Go to solution

Hi All,

 

I'm currently working on an application that interfaces with an SQL database, and I seem to have ran into a roadblock.

 

I have a multicolumn list box on my front panel which is filled in with data extracted from the database. On selecting any of the rows in the list box, another one is opened displaying another set of data extracted by a generated SQL query. At the moment I am only selecting one row at a time to view it's related data, but I want to expand such that I can select mutiple rows from the list box at a time and see all of their corresponding data.

 

With only a single selection, I can pass the index value of the selection to an Index Array Function with the database as the other input and build my SQL statement.

 

But with multiple selections, I imagine I would have to build an array on index values and use those as a reference to build the SQL statment. And I am not sure how exactly to go about doing that.

 

Here is the code that I currently have working for a single selection from the list box.

 

 

untitled.JPG

 

 

Any help is appreciated. Cheers.

0 Kudos
Message 1 of 4
(2,718 Views)
Solution
Accepted by tdog

tdog wrote:

Hi All,

 

I'm currently working on an application that interfaces with an SQL database, and I seem to have ran into a roadblock.

 

I have a multicolumn list box on my front panel which is filled in with data extracted from the database. On selecting any of the rows in the list box, another one is opened displaying another set of data extracted by a generated SQL query. At the moment I am only selecting one row at a time to view it's related data, but I want to expand such that I can select mutiple rows from the list box at a time and see all of their corresponding data.

 

With only a single selection, I can pass the index value of the selection to an Index Array Function with the database as the other input and build my SQL statement.

 

But with multiple selections, I imagine I would have to build an array on index values and use those as a reference to build the SQL statment. And I am not sure how exactly to go about doing that.

 

Here is the code that I currently have working for a single selection from the list box.

 

 

 

Any help is appreciated. Cheers.


Regarding building the array:

 

I can see hat you multicolumn listbox has not multiselection enabled, and is limited to one or zero selected item at once. To enable multiselction; simply rightclick your multicolumn listbox and change your selection mode to support multiple selected items. The NewVal at the event structure should change from a single index number to a 1D array of indexed numbers. No coding needed. Then just retrive out all the items (since you know the indexes) and create the quiry. The quiry part I dont really know (long time no see SQL), but it looks like a for loop to create the string should do the trick?

0 Kudos
Message 2 of 4
(2,685 Views)

As for the SQL statement you could change the WHERE clause to include IN, as:

 

USE pubs
SELECT pub_name
FROM publishers
WHERE pub_id in ('1389', '0736')

The above returns the publisher names for the publishers with IDs of 1389 and 0736.

0 Kudos
Message 3 of 4
(2,676 Views)

Thanks guys,

 

I got the issue sorted out. I used a 'for loop' to take one index value at a time to generate my SQL statement.

 

Cheers. 

0 Kudos
Message 4 of 4
(2,674 Views)