private static void FindBooksByName(string substring) { Console.WriteLine("\nFinding books by name '{0}':", substring); var mySqlCommand = new SQLiteCommand(@"SELECT Title, Author, PublishDate, ISBN FROM Books WHERE CHARINDEX(@substring, Title)", mySqlConnection); mySqlCommand.Parameters.AddWithValue("@substring", substring); using (var reader = mySqlCommand.ExecuteReader()) { while (reader.Read()) { var title = reader["Title"].ToString(); var author = reader["Author"].ToString(); var publishDate = (DateTime) reader["PublishDate"]; var isbn = reader["ISBN"].ToString(); var book = new Book { Title = title, Author = author, PublishDate = publishDate, Isbn = isbn }; Console.WriteLine(book); } } }
private static void ListingAllBooks() { Console.WriteLine("Listing all books: "); var mySqlCommand = new SQLiteCommand(@"SELECT Title, Author, PublishDate, ISBN FROM Books", mySqlConnection); using (var reader = mySqlCommand.ExecuteReader()) { while (reader.Read()) { var title = reader["Title"].ToString(); var author = reader["Author"].ToString(); var publishDate = (DateTime) reader["PublishDate"]; var isbn = reader["ISBN"].ToString(); var book = new Book { Title = title, Author = author, PublishDate = publishDate, Isbn = isbn }; Console.WriteLine(book); } } }