python - 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?
解决方案
Apparently I misread the setGenerated() method for QSqlRecord as changing the False to True updates the database properly.
推荐阅读
- c# - Covariance in c# is not type safe. This statement applies fine when dealing with arrays, but not when dealing with Ienumerables. Why?
- java - 从文本字段接收输入
- java - 如何根据操作系统类型更改 ansible docker_container 中的 docker 命令
- r - RStan - 非常低的 CPU 利用率
- python - 使用 seaborn 的部分多重阴影图
- python - 将列中的 0 替换为 pandas 中的 groupby 中位数
- memory-management - (DX12) 2D-Texture UAV 的回读缓冲区
- postgresql - postgresql 插入整数 PK nextval
- angular - 角度,参考变量不刷新
- excel - 性能问题 - 根据列标题重新排列列