09-18-2019 04:37 AM
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.
Solved! Go to Solution.
09-18-2019 04:40 AM
I will put the picture on later.
09-18-2019 05:22 AM
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.
09-18-2019 05:41 AM
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
09-18-2019 08:56 AM
Hi Rolf,
Thank you. I know this point, but the size of 1D array is undefined. Just see the attached picture.
09-18-2019 09:10 AM
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.
09-18-2019 09:17 AM
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.
09-18-2019 09:23 AM
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.
09-18-2019 09:47 AM
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.