I have books_table in the database. which contain Id, title ,subtitle image & others.
I have inserted the image in the string form in the database.
Now i want to display all records in the Datagrid view in windows Form.
I'm able to display all fields but unable to display the image of a book in the datagrid view.
In database Image is url stored as string
I put all the records in the genric list:
Expand|Select|Wrap|Line Numbers
- public List<Book> GetBooks()
- {
- var books = new List<Book>();
- using (DbConnection connection = new SqlConnection(connectionString))
- using (DbCommand command = connection.CreateCommand())
- {
- command.CommandText = "SELECT * FROM Book3";
- connection.Open();
- using (DbDataReader reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
- books.Add(new Book()
- {
- Id = (int)reader["Id"],
- Title = (string)reader["Title"],
- Subtitle = (string)reader["Subtitle"],
- Isbn = (string)reader["Isbn"],
- Price = Convert.ToString(reader["Price"]),
- Image = (string)reader["Image"],
- Url = (string)reader["Url"]
- });
- }
- }
- }
- return books;
- }