# Insert power table into DB table

**URL:** <https://forum.inductiveautomation.com/t/insert-power-table-into-db-table/18369>\
**Category:** Ignition\
**Created:** [June 8, 2018, 9:10pm UTC](https://forum.inductiveautomation.com/t/insert-power-table-into-db-table/18369 "2018-06-08T21:10:48Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 11, 2018, 2:15pm UTC](https://forum.inductiveautomation.com/t/insert-power-table-into-db-table/18369/11 "2018-06-11T14:15:24Z")

</div>

Got it! Thanks for help everyone

```auto
TableData = event.source.parent.getComponent('Table3').data
	
	# Convert to PyDataset (easier to loop through)
	py_TableData = system.dataset.toPyDataSet(TableData)

	po = event.source.parent.getComponent('PO Label').value
	day = event.source.parent.getComponent('DayColor').selectedStringValue
	
	# Start the transaction
	txID = system.db.beginTransaction(timeout=5000)
	
	# Loop through the rows in the dataset, and insert them into the database.
	for row in py_TableData:
		
		# Get the row data using column name, or index. I suggest column name as indexes could change
		column1 = row['STYLE'] 
		column2 = row['QUANTITY']
		column3 = row['DESCRIPTION']
		column4 = row['5x5']
		column5 = row['4x8']
		column6 = row['RB']
		column7 = row['HW']
		column8 = row['OSB']
		# Build the query (python, triple quotes allow whitespace)
		sql = """
					INSERT INTO mill_serviceorder
						(PO, DAY, STYLE, QUANTITY, DESCRIPTION, 5x5, 4x8, RB, HW, OSB)
					VALUES
						(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
				"""
		system.db.runPrepUpdate(sql, [po, day, column1, column2, column3, column4, column5, column6, column7, column8], tx=txID)
		
	# Commit and close the transaction
	system.db.commitTransaction(txID)
	system.db.closeTransaction(txID)
```

---

_[View the full topic](https://forum.inductiveautomation.com/t/insert-power-table-into-db-table/18369)._
