gpt4 book ai didi

c# - 语句与 REFERENCE 约束冲突

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:03 25 4
gpt4 key购买 nike

按钮点击代码

bindingSource1.EndEdit();
try
{
// Delete all the Channels for the current Folder.
int folderID = (int)RemoveFolderBox.SelectedValue;
deleteChannels(folderID);

// Delete the folder itself.
RSSDataSet1.FolderRow folder = rSSDataSet1.Folder.FindByFolderID(folderID);
folder.Delete();

int rowsAffected = folderTableAdapter.Update(rSSDataSet1);

if (rowsAffected > 0)
{
//statusLabel.Text = "Folder successfully deleted.";
}
}
catch (Exception ex)
{
MessageBox.Show("Problem when deleting folder:" + ex.Message);
}

删除 channel 功能:<​​/p>

private void deleteChannels(int folderID)
{
try
{
RSSDataSet1.ChannelRow[] channels = (RSSDataSet1.ChannelRow[])rSSDataSet1.Channel.Select("FolderID = " + folderID.ToString());

foreach (RSSDataSet1.ChannelRow channel in channels)
{
int channelID = channel.ChannelID;
channel.Delete();
}
int rowsAffected = channelTableAdapter1.Update(rSSDataSet1);
}
catch (Exception ex)
{
throw ex;
}
}

我得到了

The DELETE statement conflicted with the REFERENCE constraint "FK_Channel_Folder". The conflict occurred in database "C:\USERS\ADMIN\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\PROJ RSS\PROJ RSS\BIN\DEBUG\RSS.MDF", table "dbo.Channel", column 'FolderID'. The statement has been terminated.

最佳答案

如果您尝试删除的项目被删除,您有一个外键引用将被违反。看起来 Channel 有依赖于它的 Folder 实体。

在删除 Channel 之前,您需要删除任何相关的 Folder 实体,或者设置级联删除。

关于c# - 语句与 REFERENCE 约束冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6846598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com