开发者

statement conflicted with the REFERENCE constraint

开发者 https://www.devze.com 2023-03-23 02:08 出处:网络
BUTTON CLICK CODE bindingSource1.EndEdit(); try { // Delete all the Channels for the current Folder. int folderID = (int)RemoveFolderBox.SelectedValue;

BUTTON CLICK CODE

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

                开发者_如何学C// 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);
            }

deleteChannels-function:

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;
     }
}

I'm getting

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.


You have a foreign key reference that would be violated if the item you're attempting to remove was deleted. It looks like Channel has Folder entities that depend on it.

You will need to delete any dependent Folder entities before removing the Channel, or set up cascading deletes.

0

精彩评论

暂无评论...
验证码 换一张
取 消