static void Main(string[] args) { ListAllBooks(); FindBookByName("Pod Igoto"); Book book = new Book("Added book", "Minka Svircholini", "8411929473", new DateTime(2013, 01, 12)); AddBook(book); }
static void AddBook(Book book) { MySqlConnection connection = new MySqlConnection(ConnectionString); connection.Open(); using (connection) { MySqlCommand command = new MySqlCommand( "INSERT INTO Books (Title, Author, PublishDate, ISBN) " + "VALUES (@title, @author, @publishDate, @isbn)", connection); MySqlParameter titleParam = new MySqlParameter("@title", book.Title); MySqlParameter authorParam = new MySqlParameter("@author", book.Author); MySqlParameter publishDateParam = new MySqlParameter("@publishDate", book.PublishDate); MySqlParameter isbnParam = new MySqlParameter("@isbn", book.Isbn); command.Parameters.AddRange(new MySqlParameter[] { titleParam, authorParam, publishDateParam, isbnParam }); command.ExecuteScalar(); } }