更新条目时出错。有关详细信息,请参阅内部异常 [关闭]

Posted

技术标签:

【中文标题】更新条目时出错。有关详细信息,请参阅内部异常 [关闭]【英文标题】:An error occurred while updating the entries. See the inner exception for details [closed] 【发布时间】:2013-03-06 04:49:23 【问题描述】:

当我删除列表框中的项目时,我收到问题中的错误,如下面的屏幕截图所示:

我不知道内部异常在哪里,但我尝试了 try, catch 但我在问题中遇到了同样的错误。

这里是所有代码:

namespace WpfApplication7
 
/// <summary>
/// Interaction logic for Edit_Rooms.xaml
/// </summary>
public partial class Edit_Rooms : Window

    public Edit_Rooms()
    
        InitializeComponent();
    

    //initialises entities
    WpfApplication7.AllensCroftEntities1 allensCroftEntities1 = new WpfApplication7.AllensCroftEntities1();
    private Room ObjectIndex;

    private void Window_Loaded(object sender, RoutedEventArgs e)
    
        // Load data into Rooms. 
        System.Windows.Data.CollectionViewSource roomsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("roomsViewSource")));
        //runs a query to go the roomsQuery to get the rooms table from the entities
        System.Data.Objects.ObjectQuery<WpfApplication7.Room> roomsQuery = this.GetRoomsQuery(allensCroftEntities1);
        //used when adding new rooms
        roomsViewSource.Source = roomsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
    

    private System.Data.Objects.ObjectQuery<Room> GetRoomsQuery(AllensCroftEntities1 allensCroftEntities1)
    
        System.Data.Objects.ObjectQuery<WpfApplication7.Room> roomsQuery = allensCroftEntities1.Rooms;
        // Returns an ObjectQuery.
        return roomsQuery;
    

    private void btnDelete_Click(object sender, RoutedEventArgs e)
    
        //prevents user trying to delete nothing/unselected row
        if (ObjectIndex == null)
        
            MessageBox.Show("Cannot delete the blank entry");
        
        else
        
                //deletes object from dataset, saves it and outputs a message
                allensCroftEntities1.DeleteObject(ObjectIndex);
                allensCroftEntities1.SaveChanges();
                MessageBox.Show("Room Deleted");
        
    

    private void btnSave_Click(object sender, RoutedEventArgs e)
    
        try
        
            //attempts to save changes
            allensCroftEntities1.SaveChanges();
            MessageBox.Show("Saved");
        
        catch (Exception ex)
        
            //if unsuccessful, outputs an error message
            MessageBox.Show(ex.ToString());
        
    

    private void btnFirst_Click(object sender, RoutedEventArgs e)
    
        listbox.SelectedIndex = 0;
    

    private void btnPrevious_Click(object sender, RoutedEventArgs e)
    
        //prevents user going to the previous item before the first item
        if (listbox.SelectedIndex > 0)
        
            listbox.SelectedIndex -= 1;
        
    

    private void btnNext_Click(object sender, RoutedEventArgs e)
    
        //prevents user going after last item and throwing up an error
        if (listbox.SelectedIndex < listbox.Items.Count)
        
            listbox.SelectedIndex += 1;
        
    

    private void btnLast_Click(object sender, RoutedEventArgs e)
    
        listbox.SelectedIndex = listbox.Items.Count - 1;
    

    private void listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    
        //outputs index of the selected room
        ObjectIndex = listbox.SelectedItem as Room;
    


【问题讨论】:

【参考方案1】:

单击“查看详细信息...”将打开一个窗口,您可以在其中展开“内部异常”我的猜测是当您尝试删除记录时存在引用约束违规。内部异常将为您提供更多信息,以便您可以修改代码以在删除记录之前删除任何引用。

【讨论】:

【参考方案2】:

点击“查看详细信息”查找内部异常。

【讨论】:

以上是关于更新条目时出错。有关详细信息,请参阅内部异常 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章

更新条目时出错

EF sqlite3报错 "System.Data.Entity.Core.EntityException: 在提供程序连接上启动事务时出错。有关详细信息,请参阅内部异常。

实体异常:在提供程序连接上启动事务时发生错误。有关详细信息,请参阅内部异常

执行命令定义时发生错误。有关详细信息,请参阅内部异常 (linq)

创建 AVD 时出错。有关详细信息,请参阅idea.log。 Ubuntu 16.04

与 LDAP 的 Keycloak 联合无法建立连接:错误!尝试连接到 LDAP 时出错。有关详细信息,请参阅 server.log