private void btnInsert_Click(object sender, EventArgs e) { // Code that inserts Book //Book book = new Book(); //book.Title = txtTitle.Text; //book.Author = txtAuthor.Text; //book.Price = decimal.Parse(txtPrice.Text); //book.Description = txtDescription.Text; //book.CountryId = 1; //BookRepo repo = new BookRepo(); //repo.AddBook(book); //LoadBooks(); // Code that inserts Book and gives back inserted Id Book book = new Book(); book.Id = 0; book.Title = txtTitle.Text; book.Author = txtAuthor.Text; book.Price = decimal.Parse(txtPrice.Text); book.Description = txtDescription.Text; book.CountryId = 1; BookRepo repo = new BookRepo(); int value = repo.AddBookReturnId(book); MessageBox.Show(value.ToString()); LoadBooks(); }
private void btnInsertandGetId_Click(object sender, EventArgs e) { Book book = new Book(); book.Title = txtTitle.Text; book.Author = txtAuthor.Text; book.Price = decimal.Parse(txtPrice.Text); book.Description = txtDescription.Text; book.CountryId = 2; BookRepo repo = new BookRepo(); int id = repo.AddBookReturnId(book); MessageBox.Show($"The new Id in the table is: {id} "); LoadBooks(); }
private void InsertReturnId_Click(object sender, EventArgs e) { Book book = new Book { Title = txtTitle.Text, Author = txtAuthor.Text, Price = decimal.Parse(txtPrice.Text), Description = txtDescription.Text, CountryId = 1 }; int id = repo.AddBookReturnId(book); MessageBox.Show("The new Id in the table is: " + id.ToString()); LoadBooks(); }
private void btnInsertGetId_Click(object sender, EventArgs e) { var book = new Book { Title = txtTitle.Text, Author = txtAuthor.Text, Price = decimal.Parse(txtPrice.Text), Description = txtDescription.Text, CountryId = 2 }; BookRepo repo = new BookRepo(); int id = repo.AddBookReturnId(book); MessageBox.Show("Generated ID is: " + id.ToString()); LoadBooks(); }