Insert power table into DB table

Got it! Thanks for help everyone

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)
1 Like