Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine the number of rows of data in a datatable?

I have a datatable that I fill from an SQL query.  I do not know exactly how many rows of data it will return (due to my selection criteria) but will be somewhere between 100 and 300 rows.  I send this data into a report but need to determine the length of the report (panel height data member) programatically based on how much data the query has returned.  So, I need a way to count how many rows are filled in the data table.
 
I tried doing a nested "if" statement checking the value of each cell but when I tested the expression at 59 "if" statements (will need 300+) I got a parser error in lookout when I tried to accept the connection.  I also tried a type of loop by assigning cursor.2 either to its own value (circular) or to its own value plus one depending on the value of the cell at cursor.2.  It was close but overshot by one row or more (much more sometimes).
 
Any clever ideas?  Perhaps I have just been looking at this problem too long.  Thanks, in advance, for your help.
0 Kudos
Message 1 of 3
(5,278 Views)
Since the datatable gets the data from the SQL query, you can also use the SQL statement to count the number of rows in the query result.  
For example, in datatable you do "select localtime, trace1 from intdata where xxx". You can get the count by "select count(trace1) from intdata where xxx". Use the same condition in order to get the same number of rows.
Maybe another SQLExec object is needed to do the count.
Whenever the datatable executes the SQL, the SQLExec executes and return the count.
Ryan Shi
National Instruments
0 Kudos
Message 2 of 3
(5,267 Views)
Great idea Ryan!  I tried it out using a seperate SqlExec call and it worked great; even if I launch it simultaneously with the table query.  I was thinking the "count" function would count the number of data points in the database rather than the results of the query.  I was wrong.  Thanks for your help!
0 Kudos
Message 3 of 3
(5,264 Views)