# Dynamic binding tags in table

**URL:** <https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682>\
**Category:** Ignition\
**Created:** [February 15, 2017, 7:58pm UTC](https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682 "2017-02-15T19:58:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StepanenkoPaul](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@StepanenkoPaul](https://forum.inductiveautomation.com/u/StepanenkoPaul)\
**Post date:** [February 15, 2017, 7:58pm UTC](https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682/1 "2017-02-15T19:58:06Z")

</div>

I have a question about dynamic binding tags in table.  
I have table with columns:  
TagName, Description, EngUnits.  
What i want:  
execute SQL query, get tagname, description, enguints and get current values of tags using binding by tagname (system.tag.read ()).  
I have at the moment next results:

- Execute SQL query, get TagName, get current values using tagName
- Execute SQL query, get values from table by TagName

but i can not combine this queries and display their in one Table.

And another question:  
how i can convert system.db.runQuery result to dataset?

Only like that?

```auto
results = system.db.runQuery("SELECT TagName FROM sunst.points_list","SunStConnection")
event.source.parent.getComponent("Table 1").data = results
data=event.source.parent.getComponent("Table 1").data
```

or is there other options?

---

<div class="post-metadata">

**Author:** ![StepanenkoPaul](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@StepanenkoPaul](https://forum.inductiveautomation.com/u/StepanenkoPaul)\
**Post date:** [February 16, 2017, 11:19am UTC](https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682/2 "2017-02-16T11:19:12Z")

</div>

I think I solved the problem:

```auto

#clear table
myTable=event.source.parent.getComponent('Table')
header = ['id','TagName','Description','EU','Type','Value']
row = []
data = system.dataset.toDataSet(header,row)
myTable.data = data

#execute SQL query
query = system.db.runPrepQuery("SELECT * FROM sunst.points_list")
query_ds=system.dataset.toDataSet(query)

#get values from dataset
for row in range(query_ds.rowCount):
	id=query_ds.getValueAt(row,"id")
	tagname=query_ds.getValueAt(row,"TagName")
	description=query_ds.getValueAt(row,"Description")
	eu=query_ds.getValueAt(row,"EU")
	type=query_ds.getValueAt(row,"Type")

        #get current tag value
	value=system.tag.read(tagname)
	
	#create new row
	newRow=[id,tagname,description,eu,type,value.value]
       #add this new row
	data=system.dataset.addRow(data,newRow)
	
#show data
myTable.data = data

```

maybe it will be useful to someone

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [February 16, 2017, 3:48pm UTC](https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682/3 "2017-02-16T15:48:24Z")

</div>

You may want to read all the tag values at once.

[code]tagPathsToRead = []  
#get values from dataset  
for row in range(query\_ds.rowCount):  
id=query\_ds.getValueAt(row,“id”)  
tagname=query\_ds.getValueAt(row,“TagName”)  
description=query\_ds.getValueAt(row,“Description”)  
eu=query\_ds.getValueAt(row,“EU”)  
type=query\_ds.getValueAt(row,“Type”)

# Add the tagpath to the list

tagPathsToRead.append(tagname)  
#create new row  
newRow=[id,tagname,description,eu,type,None]  
#add this new row  
data=system.dataset.addRow(data,newRow)

tagValues = system.tag.readAll(tagPathsToRead)  
for row in range(query\_ds.rowCount):  
data = system.dataset.updateRow(data,row,{“Value”:tagValues[row].value})[/code]

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 16, 2017, 3:53pm UTC](https://forum.inductiveautomation.com/t/dynamic-binding-tags-in-table/12682/4 "2017-02-16T15:53:32Z")

</div>

[quote=“StepanenkoPaul”]I think I solved the problem[/quote]You could simplify this considerably if you used the PyDataSet as intended, in addition to using system.tag.readAll() to get the values in bulk:`myTable=event.source.parent.getComponent('Table')
header = ['id','TagName','Description','EU','Type','Value']
newRows = []
query = system.db.runPrepQuery("SELECT * FROM sunst.points_list")
tagNames = [row['TagName'] for row in query]
values = system.tag.readAll(tagNames)
for row, value in zip(query, values):
   newRow = [row['id'], row['TagName'], row['Description'], row['EU'], row['Type'], value.value]
   newRows.append(newRow)
myTable.data = system.dataset.toDataSet(header, newRows)`
