# Update data from a table to DB

**URL:** <https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330>\
**Category:** Archived Topics\
**Created:** [March 8, 2016, 9:00pm UTC](https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330 "2016-03-08T21:00:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [March 8, 2016, 9:00pm UTC](https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330/1 "2016-03-08T21:00:46Z")

</div>

I have used a binding function to populate data in table.In the execute() method i have done a select query operation which fills the table.  
When i change the table properties to editable and edit data, it goes back to original value since the polling is not off.

I want the data to be saved in the DB when i edit a cell in the table. How can i achieve this functionality?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 8, 2016, 9:39pm UTC](https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330/2 "2016-03-08T21:39:54Z")

</div>

An easy generic way is to go into scripting on the table.  
Select onCelledited and use a script like this.

```auto
	import system
	ID = self.data.getValueAt(rowIndex,"NavID")
	query = "UPDATE Plant_IGN_Navigation SET " + colName + " = ? WHERE NavID = ?"
	values = [newValue, ID]
	system.db.runPrepUpdate(query, values, "ECHGSQL")
	system.db.refresh(self,"data")
```

Of course replace the values above with your own table variables and update query.

---

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [March 9, 2016, 2:52am UTC](https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330/3 "2016-03-09T02:52:09Z")

</div>

Thank you MMaynardUSG for your response.

I don’t want to do scripting in onCelledited. I want the changed value and column name in my java file so that i can run an update query in the execute() method.

This has to happen only if i have a table component.But my binding function is applicable to other components also.

result = gatewayInterface.runUpdateQuery(query, datasource)

So to form the string query i need the column edited and the new and old values.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 12, 2016, 11:57am UTC](https://forum.inductiveautomation.com/t/update-data-from-a-table-to-db/11330/4 "2016-03-12T11:57:40Z")

</div>

onCellEdited is what tells you the table cell was edited and what the new and old values were.
