# system.db.runUpdateQuery

**URL:** <https://forum.inductiveautomation.com/t/system-db-runupdatequery/37026>\
**Category:** Ignition\
**Created:** [July 24, 2020, 1:02am UTC](https://forum.inductiveautomation.com/t/system-db-runupdatequery/37026 "2020-07-24T01:02:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BA\_Steve](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@BA\_Steve](https://forum.inductiveautomation.com/u/BA_Steve)\
**Post date:** [July 24, 2020, 1:02am UTC](https://forum.inductiveautomation.com/t/system-db-runupdatequery/37026/1 "2020-07-24T01:02:37Z")

</div>

I want to be able to add a row to a table / SQL database. I have made what I am trying to do more basic to try and get that working before I go any further. I have a textbox where I enter the description, and I am taking the last part ID in the SQL database and adding 1 to it for the next part ID. What I have works for the table / dataset portion of it, but I am having problems updating the SQL database. The following is my code on the button “actionPerformed” event

```auto
table = event.source.parent.getComponent('Table')
partname = event.source.parent.getComponent('partName').text
nextpartid = system.db.runScalarQuery("SELECT MAX(`part_id`) + 1 FROM parts")

table.data = system.dataset.addRow(table.data, [nextpartid, partname, partdesc, user,station, assigndate ,None ,])
system.db.runUpdateQuery("INSERT INTO parts (part_id, part_name,) VALUES (%d, %f)" % (nextpartid, partname))

```

The error I am getting is “Error executing script for event: actionPerformed on component: add.”

I am basically copying the exact same code snippet from the manual. if I run the SQL query on the database query browser it works (with fixed values instead of variable).

Any advice to get this working? Should I be going in a different direction? It seems a bit awkward updating the table and the SQL database separately.

---

<div class="post-metadata">

**Author:** ![KMuldoon](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@KMuldoon](https://forum.inductiveautomation.com/u/KMuldoon)\
**Post date:** [July 24, 2020, 6:11am UTC](https://forum.inductiveautomation.com/t/system-db-runupdatequery/37026/2 "2020-07-24T06:11:10Z")

</div>

In your scalar query, have you tried removing the single quotes? I tried running the same select query and ended up having an issue with the SQL MAX() function thinking the column name was a varchar value and failed.

---

<div class="post-metadata">

**Author:** ![BA\_Steve](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@BA\_Steve](https://forum.inductiveautomation.com/u/BA_Steve)\
**Post date:** [July 25, 2020, 12:16am UTC](https://forum.inductiveautomation.com/t/system-db-runupdatequery/37026/3 "2020-07-25T00:16:52Z")

</div>

That portion of the code always worked, and when I remove the quotes it still worked.

My error is being generated from the system.db.runUpdateQuery line of code for some reason.
