LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to transfer unknown numbers 1D Arrary to Cluster?

Solved!
Go to solution

Hello,

 

I am working on Database Writing recently. Now I need you guys help with Database writing.

 

I use 1D Arrary to Cluster API to transfer my 1D Arrary data to Cluster, then write them to Database,but 1D Array to Cluster API has the default number is 9. My 1D Array data number is undefined, somtetimes it’s 10, and sometimes it’s 20.

So how do I do to transfer my unknown numbers 1D array to Cluster? Otherwise the write data to Database API will tell me the column number doesn’t matches the parameter numbers. It seems 1D Array to Cluster API doesn’t work.

0 Kudos
Message 1 of 9
(3,112 Views)

I will put the picture on later.

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

Right click on the Array to Cluster node and select "Cluster Size..." in the menu. In the dialog enter the number of elements your cluster should contain.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 9
(3,071 Views)

I believe that setting the Cluster Size in the 1D Array to Cluster function is something you do at Edit time, not at Run Time.  This is from the Array-to-Cluster Example included in LabVIEW:  "The Array to Cluster function is polymorphic, meaning it accepts any type of array. The Cluster Size is a property of the Array to Cluster function (rather than a run-time parameter) because the cluster must have a fixed size at compile time."

 

Note, however, you can make the entire Array (of unspecified size) a member of a Cluster, along with other elements.

 

Bob Schor

0 Kudos
Message 4 of 9
(3,052 Views)

Hi Rolf,

 

Thank you. I know this point, but the size of 1D array is undefined. Just see the attached picture.

0 Kudos
Message 5 of 9
(3,011 Views)

Hi Bob,

 

Thanks for your great support.

Yes, I do this at Edit time. I get your point and will try "make the entire Array (of unspecified size) a member of a Cluster". But I don't know whether you use DB Tools Insert Data VI. The column and parameters's number  should be same. other wise you will get an error code. See the attached pictures.

Download All
0 Kudos
Message 6 of 9
(3,004 Views)
Solution
Accepted by Jim_Liu

Weird thing about "DB Tools Insert Data" is that it works with an array internally, yet doesn't accept an array as input.  It can be easily modified to do so though; just open its "DB Tools Parser" subvi and add "Array" as a extra type in the "Cluster case" (see image).  I first did this 10 years ago.  Best to make a copy of the VI.

 

-NI_Database_API.lvlib_DB Tools Parser.png

Message 7 of 9
(2,995 Views)

As you mentioned, you are trying to use a database insert which requires the # of parameters to match the number of columns.  So i'm completely lost why you are trying to handle and UNKNOWN number of array elements.  To properly insert your data, you need to not only match the number of entries, but their order must also match the order of the column names.  

If you're simply trying to make a generic insert subVI which accepts a variety of inputs, I'd recommend doing the array to cluster conversion OUTSIDE the subvi so you can convert properly.

 

If you are trying to handle the case where some of the values may be NULL, I recommend formatting an insert statement where column name is omitted from the insert if the corresponding value is NULL (empty string).  use Execute from the DB toolkit instead of the insert vi to process the insert statement.

0 Kudos
Message 8 of 9
(2,992 Views)

Hello,

 

It works now. I add Array in the subvi and removed Array to Cluster, connect the array to  DB tools insert Data directly. Now no errors.

Thank you very much.

Message 9 of 9
(2,981 Views)