我有以下代码,但似乎不起作用:
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())
此代码的输出表明没有要更新的字段;即使所有字段(除recordid外)都已更改。我漏了一步吗?你知道吗
显然,我误读了QSqlRecord的setGenerated()方法,因为将False改为True会正确更新数据库。你知道吗
相关问题 更多 >
编程相关推荐