private static void FindBookByName(string connectionString) { SQLiteConnection dbConnection = new SQLiteConnection(connectionString); dbConnection.Open(); Console.WriteLine(); Console.WriteLine("***Enter a name of a book to search***"); string input = Console.ReadLine(); using (dbConnection) { SQLiteCommand command = new SQLiteCommand(string.Format(@"SELECT Title, Author, PublishDate, ISBN FROM books WHERE Title LIKE '%{0}%'", input), dbConnection); SQLiteDataReader reader = command.ExecuteReader(); using (reader) { while (reader.Read()) { var title = reader["Title"].ToString(); var author = reader["Author"].ToString(); var publishDate = DateTime.Parse(reader["PublishDate"].ToString()); var isbn = reader["ISBN"].ToString(); var book = new Book { Title = title, Author = author, PublishDate = publishDate, Isbn = isbn }; Console.WriteLine(book); } } } }
private static void ListAllBooks(string connectionString) { SQLiteConnection dbConnection = new SQLiteConnection(connectionString); dbConnection.Open(); Console.WriteLine(); Console.WriteLine("***Listing all books***"); using (dbConnection) { SQLiteCommand command = new SQLiteCommand( @"SELECT Title, Author, PublishDate, ISBN FROM Books", dbConnection); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var title = reader["Title"].ToString(); var author = reader["Author"].ToString(); var publishDate = DateTime.Parse(reader["PublishDate"].ToString()); var isbn = reader["ISBN"].ToString(); var book = new Book { Title = title, Author = author, PublishDate = publishDate, Isbn = isbn }; Console.WriteLine(book); } } } }