Update ccnum column in already created dataset

Hi team,

I think i am stuck in somewhere didnt get any heads up.
I have local table dataset which will have rows and having column as link, title, programid. Then i am using this data to add into our DB and it was working successfully.
But then i need to add another column not in our local table but into db when i am sending data. I am using list function to send all dataset data into list and then to DB.
Requesting a response asap

  1. If you need quick response, this isn't official support and you should call the support phone line.
  2. Sounds like you are just trying to add a column to a database table? I would check out this -
    SQL ALTER TABLE Statement

Sorry @bkarabinchak.psi my bad. Column is already added i just have to add variable value into that column. An example of the same is shown below

ccNum = "CC-42"
#below script is used to send the data to db
LIMSData = self.getSibling("Table_0").props.data
pydata = system.dataset.toPyDataSet(LIMSData)
for index in range(len(pydata)):
new_ccdata = list(pydata[index])
system.db.runPrepUpdate("INSERT INTO TableName (title, link, programid) VALUES (?, ?, ?)", new_ccdata, "DB_NAME")

so what i have to do is add ccnum data into CCNUm column of the same db where i am inserting table data

Assuming it's at the end of the new_ccdata list, add your column name just after 'programid'

EDIT: Is the new data point in the first line? If so, then you would need to append it to new_ccdata

yes the new ccNum data is in first line, I have to use first line data to be inserted into table along with the insert query which i have written
I tried append but it is not working do you have any examples of the append
One point i missed is if 4 rows are inserted in local table then the ccNum value is to be updated on those 4 rows and not on 1 row.

ccNum = "CC-42"
#below script is used to send the data to db
LIMSData = self.getSibling("Table_0").props.data
pydata = system.dataset.toPyDataSet(LIMSData)
for index in range(len(pydata)):
	new_ccdata = list(pydata[index])
	# Append value
	new_ccdata.append(ccNum)
	# Run query. Note the extra column name and question mark.
	system.db.runPrepUpdate("INSERT INTO TableName (title, link, programid, cc_num_column_name) VALUES (?, ?, ?, ?)", new_ccdata, "DB_NAME")

Thanks @JordanCClark that worked as i wanted. Thanks for immediate help

1 Like