public static void Main() { Book book = new Book() { Title = "C# guru", Author = "Some Guy", PublishDate = DateTime.Now, ISBN = "439429342" }; try { using (dbcon = new SQLiteConnection(BooksOperatorSqlite.ConnectionString)) { dbcon.Open(); // CreateDB(); // PopulateDB(); InsertBook(book); FindByName(book.Title); ListAllBooks(); } } catch (Exception ex) { Console.WriteLine("If database doesn't exist or isn't populated, uncomment the appropriate method above! (CreateDB or PopulateDb)"); Console.WriteLine(ex); } }
private static void InsertBook(Book book) { SQLiteCommand command = new SQLiteCommand("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(); }