public static void Main() { //PrintBooksToConsole(); //var book = GetBookByName("pod igoto"); //Console.WriteLine($"{book.Title} - {book.Author}"); var book = new Book(title: "Stamat", author: "Mariika"); AddBook(book); }
public static void AddBook(Book book) { Console.Write("Enter pass: "******"Server=localhost;Database=Books;Uid=root;Pwd=" + pass + ";"; var connection = new MySqlConnection(connectionString); connection.Open(); var command = new MySqlCommand(cmdText: "insert into books(Title, Author, PublishDate, ISBN)" + " values(@title, @author, @date, @isbn)", connection: connection); command.Parameters.AddWithValue(parameterName: "@title", value: book.Title); command.Parameters.AddWithValue(parameterName: "@author", value: book.Author); command.Parameters.AddWithValue(parameterName: "@date", value: book.PublishDate); command.Parameters.AddWithValue(parameterName: "@isbn", value: book.Isbn); var result = command.ExecuteNonQuery(); Console.WriteLine($"({result}) row(s) affected"); connection.Close(); }