DELETE语句与REFERENCE约束“FK_tblArchieveImmigration_tblClientRecord”冲突。该语句已终止。 [英] The DELETE statement conflicted with the REFERENCE constraint "FK_tblArchieveImmigration_tblClientRecord". The statement has been terminated.
本文介绍了DELETE语句与REFERENCE约束“FK_tblArchieveImmigration_tblClientRecord”冲突。该语句已终止。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Helo那里,任何人都可以帮我解决我的问题。这是我的代码。
Helo there, anybody could help me with my problem. Here's my code.
Private Sub mnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
If dbGridClient.RowCount < 1 Then
Exit Sub
End If
Dim i As Integer
If MsgBox("You are about to delete the selected row(s)", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, sAppName) = MsgBoxResult.Yes Then
'Try
SQLCONNECT()
SQL = "DELETE FROM tblClientRecord WHERE ClientID = '" & dbGridClient.SelectedRows(0).Cells(0).Value & "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(SQL, conn)
i = cmd.ExecuteNonQuery()
cmd = Nothing
dbGridClient.Rows.Remove(dbGridClient.CurrentRow)
conn.Close()
cmd = Nothing
'Catch ex As Exception
' MsgBox(ex.ToString, MsgBoxStyle.Exclamation, sAppName)
'End Try
load_clientRecord()
Load_Client_Datagrid()
End If
End Sub
推荐答案
您正在尝试删除另一行引用的行(在另一个表中)可能)。
确保当你删除一行时,首先删除外键引用的行。
You are trying to delete a row that is referenced by another row (in another table probably).
Ensure that when you a delete a row, foreign key referenced rows are deleted first.
<br />
CASCADE DELETE
是删除父级后级联删除子行的选项。
以下是一些好文章 -
SQL Server中的CASCADE示例 [ ^ ]
使用外键的DELETE CASCADE选项 [ ^ ]
这对于保持参照完整性非常重要。
is an option that cascades delete to child rows once the parent is deleted.
Here are some good articles -
CASCADE in SQL Server with example[^]
Using DELETE CASCADE Option for Foreign Keys[^]
This is important to maintain referential integrity.
这篇关于DELETE语句与REFERENCE约束“FK_tblArchieveImmigration_tblClientRecord”冲突。该语句已终止。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文