# Advice Needed on db Update from Ignition

**URL:** <https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 28, 2024, 12:52pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528 "2024-06-28T12:52:48Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 1, 2024, 3:48pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/21 "2024-07-01T15:48:26Z")

</div>

Ok, it works but it changes every storage type and not just the one that i changed.

```python
def runAction(self, event):
	#assuming that props.data is a dataset
	rowId = self.props.data.getValueAt(event.row, "storage_type")
	#if props.data is in JSON format then it would be
	#rowId = self.props.data[event.row]["ID"]
	
	#update database with edited data.
	query = "UPDATE material_master SET {} = ? WHERE storage_type = ?".format(event.column)
	args = [event.value, rowId]
	system.db.runPrepUpdate(query,args)
	
	#refresh the binding on props.data to pull in the edited data.
	self.refreshBinding('props.data')

```

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 1, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/22 "2024-07-01T16:57:21Z")

</div>

Any idea on how to make it only update the cell that was changed?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 1, 2024, 5:05pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/23 "2024-07-01T17:05:12Z")

</div>

How do you uniquely identify a row in the DB? What is the Primary Key on that table?

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 1, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/24 "2024-07-01T17:38:30Z")

</div>

the primary key is sku.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c91d54bb3bdc18984cfa9a938e08286afe39ec81.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 1, 2024, 7:20pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/25 "2024-07-01T19:20:45Z")

</div>

Then you should be using that as your row identifier.

```python
sku = self.props.data.getValueAt(event.row,"sku")
query = "UPDATE material_master SET {} = ? WHERE sku = ?".format(event.column)
args = [event.value, sku]

```

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 2, 2024, 12:34pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/26 "2024-07-02T12:34:40Z")

</div>

Morning lrose,

To limit and issues I am doing some "testing" on an inert table.

There is a pic below.

Here is the code, I updated all of the into to reflect this new table.

I am getting this error now:

com.inductiveautomation.ignition.common.script.JythonExecException  
Traceback (most recent call last):  
File "function:runAction", line 8, in   
NameError: name 'self' is not defined

```python
def runAction(self, event):
#assuming that props.data is a dataset
	rowId = self.props.data.getValueAt(event.row, "new_sap_m")
#if props.data is in JSON format then it would be
#rowId = self.props.data[event.row]["ID"]

#update database with edited data.
sku = self.props.data.getValueAt(event.row,"sap_m_number")
query = "UPDATE z_dunnage_tare SET {} = ? WHERE sap_m_number = ?".format(event.column)
args = [event.value, sap_m_number]
system.db.runPrepUpdate(query,args)

#refresh the binding on props.data to pull in the edited data.
self.refreshBinding('props.data')

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/819c978db417af1a0342748237b975227128b174.png)

---

<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:** [July 2, 2024, 12:38pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/27 "2024-07-02T12:38:02Z")

</div>

Your indentation is broken.

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 2, 2024, 12:44pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/28 "2024-07-02T12:44:01Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 2, 2024, 12:44pm UTC](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528/29 "2024-07-02T12:44:26Z")

</div>

Thank you so much for your help!!!

[Previous page](https://forum.inductiveautomation.com/t/advice-needed-on-db-update-from-ignition/92528.md?page=1)
