public void Insert() { //Inserts the books from the data grid into the db try { Model1Container2 db = new Model1Container2(); foreach (var book in booksRead) { BookTBL newBook = new BookTBL() { Author = $"{book.Author}", Title = $"{book.Title}", AuthorTBLId = 1 }; db.BookTBLs.Add(newBook); db.SaveChanges(); } } catch (NullReferenceException nre) { MessageBox.Show(nre.Message); } catch (Exception) { MessageBox.Show("An error inserting into the database occurred"); } }
private void Button_Click(object sender, RoutedEventArgs e) { //Load books Model1Container2 db = new Model1Container2(); var query = from b in db.BookTBLs select b; dataGrid_read.ItemsSource = query.ToList(); }