【问题标题】:Key value for this row was changed or deleted at the data store. The local row is now deleted此行的键值已在数据存储中更改或删除。本地行现在被删除
【发布时间】:2015-05-03 20:53:53
【问题描述】:

将 150 万行 D7、BDE、Paradox 迁移到 XE2、ADO、MS-SQL。

我们有一个工作正常的 TDBLookupComboBox。我们为用户提供了一个省略号按钮,以便他们可以在组合框可见时从组合框的 ListSource 表中添加或删除记录。

如果用户点击省略号,我们让他们编辑表格,然后我们刷新组合框数据源,如下所示:

EditTable.ShowModal; // user edits ListSource.Dataset table
Form1.DBComboBox1.ListSource.DataSet.Refresh

这在 Paradox 世界中运行良好。

在 SQL/ADO 世界中,如果用户从 ListSource 中删除一条记录,我们会在上面的 Refresh 语句中得到消息:

Key value for this row was changed or deleted at the data store. 
The local row is now deleted.

即使用户删除的记录不是组合框中当前选定的项目,也会发生这种情况。

我们不明白为什么现在会发生这种情况,但在 Paradox 版本中却没有。

我们的解决方案是(在用户编辑后)关闭和打开 ListSource 数据集,如下所示,但这很笨拙(我们必须在近 100 个地方复制我们做这种事情。)

这是我们当前的修复:

var
  KeyBeforeUserEdit: Integer;

KeyBeforeUserEdit:= Form1.DBComboBox.KeyValue;
EditTable.ShowModal; // user edits ListSource.Dataset table
Form1.DBComboBox1.ListSource.DataSet.Close;
Form1.DBComboBox1.ListSource.DataSet.Open;
if Form1.DBComboBox1.ListSource.DataSet.Locate('UniqueKey', KeyBeforeUserEdit, []) then 
  From1.DBComboBox1.KeyValue := KeyBeforeUserEdit; 

任何其他建议或解释为什么这是必要的?

【问题讨论】:

  • 很难说哪里出了问题,可能您必须构建一个描述问题的示例应用程序。另一种解决方案是对分离的数据集进行操作(恕我直言,ADO 的一大特点)并手动更新它。

标签: delphi ado


【解决方案1】:

我无法确定发生了什么,但您可以通过以下方式简化迁移(尽管不是好的做法)。

ShowModal 是一个虚函数,因此您可以在 EditTable 所属的类(TEditTable?)中覆盖它,前提是您有该源。在单元内将 Form1 单元添加到使用子句在实施部分(如果还没有的话)并按如下方式添加您的覆盖

function TEditTable.ShowModal : integer;
var
  KeyBeforeUserEdit: Integer;
begin
  KeyBeforeUserEdit:= Form1.DBComboBox.KeyValue;
  Result := inherited ShowModal; // user edits ListSource.Dataset table
  Form1.DBComboBox1.ListSource.DataSet.Close;
  Form1.DBComboBox1.ListSource.DataSet.Open;
  if Form1.DBComboBox1.ListSource.DataSet.Locate('UniqueKey', KeyBeforeUserEdit, []) then 
    From1.DBComboBox1.KeyValue := KeyBeforeUserEdit; 
end;

这有点杂乱无章,但可能是务实的,可以节省很多工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 2018-02-04
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多