Thanks for your reply, still learning databases. I seem to be missing something
# If dragging to another table, rather than itseelf.
if self != sourceTable:
#Get the current dataset of the destination table. All the rows
destDataset = self.getData()
#Convert the row that was dragged from the source table, to a py dataset
pyRowData = system.dataset.toPyDataSet(rowData)
#Loop through all rows that were selected (should just be 1)
#And then loop through each column, adding it to the 'newRow' array
#Then, add the new row to the destination dataset.
for row in pyRowData:
newRow = []
for column in row:
newRow.append(column)
destDataset = system.dataset.addRow(destDataset, dropIndexLocation, newRow)
# Add the entire dataset to the table object
self.setData(destDataset)
# Deletes the dragged rows from the source table.
# rows is actually an array, but we are only selecting one row
sourceDataset = system.dataset.deleteRows(sourceTable.getData(), rows)
sourceTable.setData(sourceDataset)
#Dragging to itself
else:
#Convert the dragged row to a pyDataSet
pyRowData = system.dataset.toPyDataSet(rowData)
#Get the number of rows originally in the dataset, used to calculate index later
sourceDataset_OrignalCount = self.getData().getRowCount()
#Delete the row from the dataset
sourceDataset = system.dataset.deleteRows(self.getData(), rows)
#Loop through the dragged row data, and add it to the dataset
for row in pyRowData:
newRow = []
for column in row:
newRow.append(column)
#If dragging to the row after the last one, there will need to be an adjustment made.
#The index was deleted earlier, so the new one will be out of range.
#We need to reduce the index by 1
if sourceDataset_OrignalCount == dropIndexLocation:
sourceDataset = system.dataset.addRow(sourceDataset, dropIndexLocation-1, newRow)
#If the row was not dragged to the end, nothing needs to be changed
else:
sourceDataset = system.dataset.addRow(sourceDataset, dropIndexLocation, newRow)
# Add the altered dataset back to the table object.
self.setData(sourceDataset)
# This example will take a dataset from a table component, and insert new records into the database, one row at a time
# Read the contents of the table
tableData = event.source.parent.getComponent('PT').data
# Convert it to a PyDataset. This is mostly for convenience, as they're easier to iterate through
pyData = system.dataset.toPyDataSet(tableData)
# Build the query we'll use. You could easily modify the line to accommodate the table you're trying to insert into.
query = "INSERT INTO proSchedule_D1 (CaseAmt, Date, Description, Line, Lot, MO, Product) VALUES (?, ?, ?, ?, ?, ?, ?)"
# Iterate
for row in pyData:
# Build an arguments list based on the current row. Using indexing here, so 'row[0]' is the 1st column, 'row[1]' is the 2nd column, etc
args = [CaseAmt, Date, Description, Line, Lot, MO, Product]
# Add a row to the database. You could optionally check the contents of the row first, and add an if-statement to prevent the record based on some criteria
system.db.runPrepUpdate(query, args,)