数据窗口错误:检索和更新之间行发生更改
更新数据窗口时出现错误,显示“检索和更新之间的行已更改”。解决办法是什么?
I am getting an error when updating a DataWindow which says "Row changed between retrieve and update". What is the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您在多个(非共享)数据窗口中显示相同的行,然后尝试同时更新它们,则可能会发生这种情况。其他原因是 SetItemStatus() 的使用不正确; update() 语句中状态标志的错误使用;最后,这是要检测的原因,另一个用户在您之前更新了该行。
This can occur if you are displaying the same row(s) in more than one (non-shared) DataWindow and then try to update them both. Other causes are incorrect use of SetItemStatus(); incorrect use of the status flags on the update() statement; and finally, the cause this is intended to detect, another user updated the row before you.
这个问题解决了吗?发生这种情况的原因有多种,其中之一是该行已被其他用户更新。在数据对象的更新属性中,您可以选择更新方法,使用键值、键和修改值,或键和所有可更新列。
如果您确定不存在并发问题,那么您可以将此设置更改为“仅使用键值”。它将使得更新的 where 子句仅包含键值,并且不会评估其他列的更改。
如果发生验证错误,则可能会发生这种情况,您需要记住将项目状态设置为未修改。要将所有行设置为不修改,您需要执行 dw_1.setitemstatus(1,0,Primary!,NotModified!) 如果我的记忆正确的话,会将第一行的所有列设置为 NotMofidied!。您还可以执行 ResetUpdate() 或重新检索数据。
希望这有帮助。
富有的
Has this been resolved? There are several reasons this could happen, one is if the row has been updated by another user. In the update properties of your dataobject you can choose update method, either using key value, key and modified values, or key and all updatable columns.
If you are SURE there is not concurrency concerns then you can change this setting to "use key value only". It will make the where clause for updates consist of the key value only and other columns will not be evaluated for changes.
It can happen if validation errors occur, you need to remember to set the item status to not modified. To set all rows to not modified you'd do dw_1.setitemstatus(1,0,Primary!,NotModified!) if my memory is correct that would set all columns for row one to NotMofidied!. You can also do a ResetUpdate() or Reretrieve the data.
hope this helps.
Rich
这通常意味着您包含在 update where 子句中的某些列正在其他地方更新,例如通过触发器。另一个原因包括在与 Oracle 通信时没有为字符串列设置空字符串为空。 oracle 将发送给它的任何空字符串转换为 null,因此后续更新不会找到同一行,除非您告诉 pb 将其也视为 null。查看您告诉 pb 包含在 where 子句(在更新规范中)中的列,并确保它们确实是您需要的列。
This usually means that some column youve included in the update where clause is bing updated somewhere else, such as through a trigger. another causes include not having empty string is null set for string columns when talking to oracle. oracle converts any empty string send to it to nulls, so a subsequent update wont find the same row unless you tell pb to treat it as null as well. look at the columns you've told pb to include in the where clause ( in the update specs ) and make sure they are really columns you need to have there.
我意识到这是一个老问题,但我想我会添加我的解决方案,以防它对任何人有帮助。在我的例子中,数据窗口发出一个 UPDATE 语句,当该语句在 SQL Management Studio 中运行时,返回的列与预期相匹配。但是,查询显示两次(1 行受影响)。触发器正在更新与正在更新的表无关的行。向该触发器添加
SET NOCOUNT ON
会导致 1 个实例(1 行受到影响),并且检索和更新之间的行更改已得到解决。I realize this is an old question, but figured I'd add my solution in case it helps anyone. In my case, the datawindow was issuing an
UPDATE
statement and when that statement was run in SQL management studio, the columns returned match what should have been expected. However, the query showed two times where (1 row(s) affected). A trigger was updating a row not related to the table being updated. AddingSET NOCOUNT ON
to that trigger resulted in 1 instance where (1 row(s) affected) and the Row Changed between retrieve and update was resolved.当您有两个数据窗口行更新同一数据库行时,也会发生这种情况。
(不太好)示例:
表没有主键,但数据窗口使用 DateOfBirth。
请注意,丹尼斯和凯特有相同的出生日期。
让我们假设进行了这些更改,
当调用 dw_1.update() 时,会出现以下消息:
因为每行更新了两次,首先是“Mr.”。丹尼斯·米勒”,然后是“丹尼斯·米勒女士”。凯特·卡普肖
This can also happen when you have two datawindow rows that update the same database row or rows.
(A not-so-good) Example:
The table has no primary key, but the datawindow uses the DateOfBirth.
Notice that Dennis and Kate have the same DateOfBirth.
Let us presume that these changes are made
When dw_1.update() is invoked, this message appears:
because each row was updated twice, first with 'Mr. Dennis Miller' and then with 'Ms. Kate Capshaw'
另一种可能性是数据窗口列定义与数据库列定义不匹配。
示例:
columnA 在数据库中定义为 char(10)
datawindow 是使用 columnA 构建的,作为 char(10)
columnA 在数据库中更改为 char(20)
数据从外部添加到 columnA,且长度超过 10 个字符。
p>
datawindow 检索截断为 10 个字符(有或没有错误,具体取决于应用程序设置。)
删除/更新行可能会产生“在检索和更新之间更改行”
Another possibility is that the datawindow column definition does not match the database column definition.
Example:
columnA is defined in database as char(10)
datawindow is built with columnA as char(10)
columnA is altered to char(20) in database
data is added externally to columnA with more than 10 characters.
datawindow retrieve truncates to 10 characters (with or without error depending on application settings.)
delete/update row may yield "Row changed between retrieve and update"
此行为由数据窗口的“更新属性”监控,更具体地说,由“更新/删除的Where 子句”部分监控。这控制 Powerbuilder 在更新时使用的“where”子句。删除,您可以使用数据窗口的 SQLPreview 事件进行检查:
现在您可以根据应用程序的具体情况选择其中之一。
This behavior is monitored by the 'Update properties' of your datawindow and more specifically by the part 'Where clause for Update/Delete'. This controls the 'where' clause that will be used by Powerbuilder upon updating.deleting, as you could check by using the SQLPreview event of your Datawindow:
Now it is up to you to choose one of these, depending on the specific context of your application.