public static void Main() { Console.Write("Please enter local mysql username: "******"Password: "******"C# guru", Author = "Some Guy", PublishDate = DateTime.Now, ISBN = "439429342" }; try { using (dbcon = new MySqlConnection(connectionString)) { dbcon.Open(); InsertBook(book); FindByName(book.Title); ListAllBooks(); } } catch (Exception ex) { Console.WriteLine("Make sure you've run the query in the project folder to generate the database."); Console.WriteLine("Also make sure that the entered username and passwork are valid."); } }
private static void InsertBook(Book book) { MySqlCommand command = new MySqlCommand("INSERT INTO Books(Title, Author, PublishDate, ISBN) VALUES (@title, @author, @publishDate, @isbn)", dbcon); command.Parameters.AddWithValue("@title", book.Title); command.Parameters.AddWithValue("@author", book.Author); command.Parameters.AddWithValue("@publishDate", book.PublishDate); command.Parameters.AddWithValue("@isbn", book.ISBN); command.ExecuteNonQuery(); Console.WriteLine("Successfully added book to db!"); Console.WriteLine(); }