外键为何会影响表的记录的添加?
请大侠们来帮帮忙
Dim rctgoods As New ADODB.Recordset
Dim strgoods As String
'Dim n As Integer
Private Sub Command1_Click()
rctgoods.Fields("数量") = rctgoods.Fields("数量") - Val(Text2.Text)
rctgoods.Update
frm_store.Adodc1.Refresh
strgoods = "select *from sell"
Dim rctgoods2 As New ADODB.Recordset
querydata strgoods, rctgoods2, 1
rctgoods2.addnew
rctgoods2.Fields("型号") = Trim(Text6.Text)
rctgoods2.Fields("数量") = Val(Text2.Text)
rctgoods2.Fields("客户") = Trim(Text1.Text)
rctgoods2.Fields("电话") = Trim(Text3.Text)
rctgoods2.Fields("备注") = Text4.Text
rctgoods2.Fields("适合机型") = Trim(Text5.Text)
rctgoods2.Fields("售价") = Val(Text7.Text)
rctgoods2.Fields("订货日期") = Date
rctgoods2.Update
rctgoods2.Close
Unload Me
End Sub
是这样的,我有两个表,其中一个表叫SELL,其每列的字段就是上面的代码中的,还有一个表叫CONTACT,它的主键 “姓名”也就是SELL表的“客户”的外键,现在CONTACT是空的,而SELL表已经有了4条记录,执行上面的操作时系统提示错误说 INSERT 语句与外键相冲突
[解决办法]
CONTACT是空的,就不能有客户。