简体   繁体   English

为什么我的子表单在MS Access 2007的INS​​ERT操作中不包含来自父表单的外键?

[英]Why is my subform not including the Foreign Key from the parent form in the INSERT operation in MS Access 2007?

The problem 问题

When I insert a new record in a multiple item subform, it throws an error as it hasn't included the required foreign key from the parent form. 当我在多项目子表单中插入新记录时,由于未包含父表单所需的外键,因此会引发错误。 The foreign key isn't allowed to be null, and it's trying to insert a null value. 外键不允许为空,它试图插入一个空值。

A bit more information 多一点信息

This process worked fine previously, but I have since upgraded my backend from ACE to SQL Server 2005. It now throws this error: 此过程以前工作正常,但此后我已将后端从ACE升级到SQL Server2005。现在会引发以下错误:

Run-time error '3146':
ODBC--call failed.
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into
column 'EngagementLetterID_FK', table 'ClientDatabase.dbo.Services'; column does
not allow nulls. INSERT fails. (#515) [Microsoft][ODBC SQL Server Driver][SQL
Server]The statement has been terminated. (#3621)

As quick comment, the subform is for Service records, and the parent form is for EngagementLetter records. 作为快速注释,该子表单用于服务记录,而父表单用于EngagementLetter记录。 One EL has many Services. 一个EL具有许多服务。

I've checked the table set up, and it seems fine, but I would say the table is operating as it should - it shouldn't allow a null value. 我已经检查了表的设置,看起来还不错,但是我想说表正在按其应有的方式工作-它不应允许空值。 Neither do I think SQL Server should be responsible for identifying the correct FK - the frontend should do this. 我也不认为SQL Server应该负责识别正确的FK-前端应该这样做。 However, my front end was working fine before with the ACE backend. 但是,在使用ACE后端之前,我的前端工作正常。 So I'm having trouble finding out what the culprit is, and I can't figure out how to do more advanced Access debugging (eg beforeUpdate, tell me what the SQL INSERT query will be). 因此,我很难找出问题的根源,也无法弄清楚如何进行更高级的Access调试(例如,在Update之前,请告诉我SQL INSERT查询将是什么)。

I've checked some of my other parent-sub forms, and they are behaving fine. 我检查了一些其他的父子表单,它们表现良好。

Any ideas? 有任何想法吗?

One other detail that I forgot to mention - I had done some dramatic front end rebuilding at the same time. 我忘记提及的另一个细节-我同时进行了一些戏剧性的前端重建。 With the subform, I had not correctly linked EngagementLetterID_FK with EngagementLetterID from the parent form. 对于子窗体,我没有正确地将父窗体的EngagementLetterID_FK与EngagementLetterID链接。 The result of this is that a new Service record has not had the EngagementLetterID_FK specified. 结果是新的服务记录未指定EngagementLetterID_FK。

So now that I have corrected the link, it's working fine. 因此,既然我已经纠正了链接,它就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM