首页 > 解决方案 > QSqlRecord not updating Database

问题描述

I have the following code which does not seem to work:

model = QSqlTableModel()
model.setTable("clidata")
model.setFilter("recordid=1")
model.select() #Only one record is loaded

record = model.record()
for ndx in range(0, record.count()):
    record.setGenerated(ndx, False)
record.setValue("recordid", 1)
record.setValue("companyname", "TEST")
record.setValue("address", "ADDRESS")
record.setValue("taxid", "TAX ID")
record.setValue("active", 2)

model.setRecord(0,record)
model.submitAll()
print(model.lastError().text())

The output for this code indicates that there are No Fields To Update; even though all the fields (except recordid) have changed. Am I missing A step?

标签: pythonpython-3.xpyqtpyqt5

解决方案


Apparently I misread the setGenerated() method for QSqlRecord as changing the False to True updates the database properly.


推荐阅读