[c#] An error occurred while updating the entries. See the inner exception for details

When i delete an item in a listbox, i get the error in the question as shown in the screenshot below: error

I do not know where the inner exception is, but i tried try, catch but i got the same error in the question.

Here is all of the code :

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

This question is related to c# sql wpf database entity-framework

The answer is


Click "view details" to find the inner exception.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to wpf

Error: the entity type requires a primary key Reportviewer tool missing in visual studio 2017 RC Pass command parameter to method in ViewModel in WPF? Calling async method on button click Setting DataContext in XAML in WPF How to resolve this System.IO.FileNotFoundException System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll? Binding an Image in WPF MVVM How to bind DataTable to Datagrid Setting cursor at the end of any text of a textbox

Examples related to database

Implement specialization in ER diagram phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' cannot be loaded Room - Schema export directory is not provided to the annotation processor so we cannot export the schema SQL Query Where Date = Today Minus 7 Days MySQL Error: : 'Access denied for user 'root'@'localhost' SQL Server date format yyyymmdd How to create a foreign key in phpmyadmin WooCommerce: Finding the products in database TypeError: tuple indices must be integers, not str

Examples related to entity-framework

Entity Framework Core: A second operation started on this context before a previous operation completed EF Core add-migration Build Failed Entity Framework Core add unique constraint code-first 'No database provider has been configured for this DbContext' on SignInManager.PasswordSignInAsync The instance of entity type cannot be tracked because another instance of this type with the same key is already being tracked Auto-increment on partial primary key with Entity Framework Core Working with SQL views in Entity Framework Core How can I make my string property nullable? Lazy Loading vs Eager Loading How to add/update child entities when updating a parent entity in EF