424,066 Members | 2,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,066 IT Pros & Developers. It's quick & easy.

How to display image from database to datagridview

P: 1
Hello,
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
  1. public List<Book> GetBooks()
  2.         {
  3.             var books = new List<Book>();
  4.             using (DbConnection connection = new SqlConnection(connectionString))
  5.             using (DbCommand command = connection.CreateCommand())
  6.             {
  7.                 command.CommandText = "SELECT * FROM Book3";
  8.                 connection.Open();
  9.                 using (DbDataReader reader = command.ExecuteReader())
  10.                 {
  11.                     while (reader.Read())
  12.                     {
  13.                         books.Add(new Book()
  14.                         {
  15.                             Id = (int)reader["Id"],
  16.                             Title = (string)reader["Title"],
  17.                             Subtitle = (string)reader["Subtitle"],
  18.                             Isbn = (string)reader["Isbn"],
  19.                             Price = Convert.ToString(reader["Price"]),
  20.                             Image = (string)reader["Image"],
  21.                             Url = (string)reader["Url"]
  22.                         });
  23.                     }
  24.                 }
  25.             }
  26.             return books;
  27.         }
2 Weeks Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.