【发布时间】:2018-09-28 09:23:49
【问题描述】:
我将 ADODB.Recordset 与 PostgreSQL 表连接起来:
Set rs.ActiveConnection = con
rs.Source = psql
rs.LockType = adLockPessimistic
rs.CursorType = adOpenKeyset
rs.index = "id"
rs.Open
我可以更新数据:
rs!somefield = "somevalue"
rs.update
我可以添加数据:
rs.AddNew
rs!someRequiredFiled = "somevalue"
rs.update
但更新数据不起作用,如果在后台更改数据:
rs!somefield = "somevalue"
// .... the same field was changed for an other user
rs.update
// -> Error, cause the field to be changed is not found anymore
我认为问题在于,Recordset 没有被告知主键。对?以及如何设置主键?
【问题讨论】:
-
您需要提供更多细节。您使用的是服务器端游标还是客户端游标? (
Debug.Print con.CursorLocation)。记录的主键是否被更改? (这是一个严重的坏习惯,主键不应该改变) -
Connection 和 Recordsetl 的 CursorLocation 为 2。如果没有手动设置到pk,则索引为空。
-
我添加了一行代码将 Recordset 的 cursorLocation 设置为 Client 并且更新效果很好。还解决了第二个问题:在连接的表单中更新无效 - 包括关于冲突的弹出对话框。但我认为我出售 rs.index 属性或让它为空都没关系。
标签: postgresql ms-access adodb