Sumonto Mehedi

Sumonto Mehedi

  • 1.8k
  • 107
  • 536

Error: when Image data convert to pdf from DataGridView tbl.

Feb 26 2020 1:07 PM
Im trying to convert DataGridView data with image column which is filtered from my SQL Db into a PDF file in C# I wrote this code using iTextSharp!
but I got  Error like this: "unable to cast object of type System.Drawing.bitmap to type system byte[]"
Can anyone help me out kindly?
Here is My Code:
Thanks !!!
 
  1. foreach (DataGridViewCell cell in row.Cells)  
  2. {  
  3.     if(row.Cells[0].Value!= null)  
  4.     {  
  5.         pdfTable.AddCell(row.Cells[0].Value.ToString());  
  6.     }  
  7.       
  8.     if (row.Cells[1].Value != null)  
  9.     {  
  10.         byte[] img = (byte[])row.Cells[1].Value;  
  11.         pdfTable.AddCell(iTextSharp.text.Image.GetInstance(img));  
  12.    }  

 

Answers (17)