Reading SELECT query results

i have written a query to fetch specific information from database table, the query is:

results= system.db.runPrepQuery("SELECT BAY_NO FROM rellocation_logic WHERE PRODUCT =? and CURRENT_TRUCK_COUNT < MAX_TRUCK COUNT ", [ProdName])

now the query will return number of rows…

Currently i am moving the result of a query in temporary table component and reading the data one by one by using tables getValueAt function

how to read the data from each row and write it to the tag with out moving it into table component .

( i am writing this script in script library [project] )

Hello,

Once you get the result of your datasbase query you can loop through it and write to tags. Here’s an example:

for index,row in enumerate(result): system.tag.write("tagpath"+str(index),row["col1"])

Best,

thanks for the reply,

but if query returns no rows, than how to check that??

It would be easier to help if you showed us more of your script (please use the code /code markers so we can see the indents). But in the meantime, you should know that the .getDataAt() method is part of the platform dataset object, not the table component itself. You can get a platform dataset from a pydataset by running the pydataset through the system.dataset.toDataSet() function, or by accessing the undocumented .underlyingDataset property. No need to put the dataset in a table. The platform dataset object has a rowCount property you can use.

Like this:

if len(result) == 0: print "no rows" else: print "%s rows"% len(result)Best,

Thank you pturmel and nmudge for your help…