# Database Update

**URL:** <https://forum.inductiveautomation.com/t/database-update/3904>\
**Category:** Ignition\
**Created:** [January 24, 2012, 1:49am UTC](https://forum.inductiveautomation.com/t/database-update/3904 "2012-01-24T01:49:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [January 24, 2012, 1:49am UTC](https://forum.inductiveautomation.com/t/database-update/3904/1 "2012-01-24T01:49:47Z")

</div>

Can someone tell me why the Edit Mode portion of this code won’t work?? The Add Mode portion works just fine, but not the Edit.

[code]varFacilNmbr = event.source.parent.Facility\_Number  
varProdCodeNmbr = event.source.parent.Prod\_code\_Nmbr  
varProdCode = event.source.parent.getComponent(‘ProductCode’).text  
varIng1 = event.source.parent.getComponent(‘Ing1DrpDwn’).selectedLabel  
varIng1Pct = event.source.parent.getComponent(‘Ing1\_Prcnt’).text

if (varProdCode == “” or varIng1 == “” or varIng1Pct == “”):  
system.gui.messageBox(“Please enter Product Parameters”)  
else:  
if varProdCodeNmbr \> 0:  
# Edit mode  
varProdCodeNmbr = system.db.runPrepUpdate(“UPDATE productcode SET ProductCode, Ing\_1, Ing\_1\_Pct = ?,?,? WHERE idproductcode = ?”,  
[varProdCode, varIng1, varIng1Pct, varProdCodeNmbr])  
else:  
# Add mode  
varProdCodeNmbr = system.db.runPrepUpdate(“INSERT INTO productcode (Facility\_Nmbr, ProductCode, Ing\_1, Ing\_1\_Pct) VALUES (?,?,?,?)”,  
[varFacilNmbr, varProdCode, varIng1, varIng1Pct], getKey=1)

system.nav.closeParentWindow(event)[/code]

Its probably obvious, but I’m sure hung up on it. (Note: Already tried removing the selectedLabel, and that didn’t work either)  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 24, 2012, 10:26am UTC](https://forum.inductiveautomation.com/t/database-update/3904/2 "2012-01-24T10:26:42Z")

</div>

Try something like:

`varProdCodeNmbr = system.db.runPrepUpdate("UPDATE productcode SET ProductCode=?, Ing_1=?, Ing_1_Pct = ? WHERE idproductcode = ?",
      [varProdCode, varIng1, varIng1Pct, varProdCodeNmbr])`

providing some degree of separation may help resolve that.

---

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [January 24, 2012, 6:13pm UTC](https://forum.inductiveautomation.com/t/database-update/3904/3 "2012-01-24T18:13:50Z")

</div>

Jordan,  
That minor modification that you suggested made all the difference in the world. Thanks a million! 😉

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 24, 2012, 7:08pm UTC](https://forum.inductiveautomation.com/t/database-update/3904/4 "2012-01-24T19:08:48Z")

</div>

No problem. As with most things programatical, it does what we tell it to do, not what we want it to do… 😆
