“数据已被改变".从主窗体过渡到子窗体时出错 [英] "The data has been changed" error when stepping from main form into sub form

查看:102
本文介绍了“数据已被改变".从主窗体过渡到子窗体时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server迁移助手(SSMA)将Access数据库迁移到SQL Server. Access应用程序将继续使用,但将使用链接表而不是本地表.

I'm migrating an Access database to SQL Server using the SQL Server Migration Assistant (SSMA). The Access application will continue to be used but with linked tables instead of local ones.

在迁移后测试期间,我遇到了一个包含多个子表单的表单问题.

I've run into a problem during the post-migration testing with a form that contains several sub forms.

测试步骤:

1)在主表单中编辑一个字段;

1) Edit a field in the main form;

2)将焦点转移到子表单中的字段;

2) Shift focus to a field in the sub form;

3)尝试编辑子表单中的字段.

3) Attempt to edit the field in the sub form.

结果:弹出错误消息:数据已更改.另一位用户在尝试保存更改之前,编辑了该记录并保存了更改."

Result: An error message pops up: "The data has been changed. Another user edited this record and saved the changes before you attempted to save your changes."

一旦消除了错误消息,就可以编辑子表单中的字段.如果未编辑主表单中的字段,则可以编辑子表单,而不会出现错误消息.

Once the error message is dismissed the field in the sub form can be edited. If the field in the main form is not edited the sub form can be edited without the error message.

关于什么可能导致此错误的任何想法?

Any ideas about what could be causing this error?

我尝试将主表单记录保存在主表单上的子表单控件的Enter事件处理程序中(即,当输入包含子表单的控件而不是子表单时,此事件发生在主表单上)形式本身).没有任何区别.我尝试在同一子表单控件Enter事件中重新查询主表单,但这不起作用-重新查询主表单会将焦点从子表单移开,因此无法对其进行编辑.

I've tried saving the main form record in the Enter event handler for the sub form control on the main form (ie this event happens on the main form, when entering the control that contains the sub form, not on the sub form itself). Doesn't make any difference. I tried requerying the main form in the same sub form control Enter event but that doesn't work - requerying the main form moves the focus away from the sub form so it can't be edited.

一个MS论坛建议在子窗体的After_Update事件中使用Me.Parent.Requery.那也不起作用.

An MS forum suggested Me.Parent.Requery in the After_Update event of the sub form. That didn't work either.

当我进入子表单时,SQL Profiler显示单个更新语句,用于更新主表单基础的表.没有其他命中数据库的语句可以修改数据.

SQL Profiler shows a single update statement, updating the table underlying the main form, when I step into the sub form. There are no other statements hitting the database that modify data.

我注意到的一件有趣的事情:主窗体的记录源实际上是将两个表连接在一起的select语句.主窗体包含可更新记录源"中每个表中的列的字段.在主窗体中编辑关系中更新子表的字段不会导致数据已更改"错误.仅当编辑用于更新关系中父表的字段时,才会发生该错误.我尝试过使用字段来更新两个表中每个表的不同列.结果是一致的:编辑父表中的记录会导致错误,而编辑子表中的记录不会.

One interesting thing I've noticed: The Record Source for the main form is actually a select statement that joins two tables together. The main form contains fields that can update columns in each of the tables in the Record Source. Editing fields in the main form that update the child table in the relationship do not cause the "data has been changed" error. The error only occurs when editing fields that update the parent table in the relationship. I've tried fields that update different columns in each of the two tables. The results are consistent: Editing the record in the parent table causes the error, editing the record in the child table does not.

子窗体和主窗体之间的链接将子窗体表中的列连接到主窗体的记录源中的子表中的列.

The link between the sub form and the main form joins a column in the sub form table to a column in the child table in the main form's Record Source.

顺便说一句,实际上主记录格式的表是以1:1关系连接的(子表中有一个记录,父表中的每个记录).子表只是父表的扩展表.

By the way, the tables in the main form Record Source are actually joined in a 1:1 relationship (one record in the child table for every record in the parent table). The child table is just an extension table for the parent table.

如果我从头开始,我个人不会设计这样的系统,但这是我必须使用的系统,我希望可以找到一些相当容易的修复方法,而无需对产品进行重大的重新设计.表格或表单(鉴于主表单和子表单各有100多个控件).

I personally wouldn't design the system like this if I was starting from scratch but it's what I've got to work with and I'm hoping there is some reasonably easy fix that won't require a major redesign of the tables or forms (given the main form and sub form each have over 100 controls).

推荐答案

经过反复尝试,我解决了这个问题.在主窗体上子窗体控件的enter事件处理程序中,我重新查询了子窗体本身.

After much trial and error I solved the issue. In the enter event handler for the sub form control on the main form, I requeried the sub form itself.

例如在主要形式上:

Private Sub Subform1_Enter()
    Me.Subform1.Form.Requery
End Sub

我不知道为什么会这样,只有那样才行.

I don't know why this works, only that it does.

这篇关于“数据已被改变".从主窗体过渡到子窗体时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆