# Populating Text Fields With Query Results

**URL:** <https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245>\
**Category:** Ignition\
**Created:** [February 23, 2023, 9:08pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245 "2023-02-23T21:08:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Hellner](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Robert\_Hellner](https://forum.inductiveautomation.com/u/Robert_Hellner)\
**Post date:** [February 23, 2023, 9:08pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245/1 "2023-02-23T21:08:34Z")

</div>

I have a Named Query "SelectData":

Select short , long , part ,  
length , location , height , number ,  
position01 , position02, position03, position04 , position05 ,  
position06 , position07 , position08 , position09 , position10 ,  
position11 , position12 , position13 , position14 , position15 ,  
position16 , position17 , position18 , position19 , position20 ,  
position21 , position22 , position23 , position24 , position25 ,  
position26 , position27 , position28 , position29 , position30  
from table  
where name = :qname

This works fine, I tested it.

Now I have a button and I want to place query results into Text Fields.  
Under the button action:

#grab query value  
qname = event.source.parent.getComponent('Text Field 3').text

#run query  
result = system.db.runNamedQuery("SelectData", {"qname":qname})

#Place Results in Text Fields  
event.source.parent.getComponent('Text Field 1').text = result["short"]  
event.source.parent.getComponent('Text Field 2').text = result["long"]

I get errors on the placing of the results in text fields.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 23, 2023, 9:16pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245/2 "2023-02-23T21:16:37Z")

</div>

Your named query is likely returning a _dataset_ - even if there's only one row, you can't access it just by column name like that. You probably want `event.source.parent.getComponent('Text Field 1').text = result.getValueAt(0, "short")`.

[https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset](https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset)

---

<div class="post-metadata">

**Author:** ![Robert\_Hellner](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Robert\_Hellner](https://forum.inductiveautomation.com/u/Robert_Hellner)\
**Post date:** [February 23, 2023, 9:19pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245/3 "2023-02-23T21:19:47Z")

</div>

OK I tried it. Same error:  
TypeError: 'com.inductiveautomation.ignition.common.BasicDataset' object is unsubscriptable

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 23, 2023, 9:55pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245/4 "2023-02-23T21:55:19Z")

</div>

Paste your code, because that error is caused by the code you originally had, not the code I wrote.

---

<div class="post-metadata">

**Author:** ![Robert\_Hellner](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Robert\_Hellner](https://forum.inductiveautomation.com/u/Robert_Hellner)\
**Post date:** [February 23, 2023, 9:56pm UTC](https://forum.inductiveautomation.com/t/populating-text-fields-with-query-results/70245/5 "2023-02-23T21:56:48Z")

</div>

The solution I found was to convert the dataset to python dataset.

This worked:  
pyData = system.dataset.toPyDataSet(result)  
event.source.parent.getComponent('Text Field 1').text = pyData[0][1]  
event.source.parent.getComponent('Text Field 4').text = pyData[0][4]
