none
Cannot display image database field RRS feed

  • Question

  • I have a report (RDLC) designed in VS2010.  One of the columns is an IMAGE field from the database (SQL Server 2008).  I have dropped an image object on the table and set the settings appropriately.  Source = database, field name set to image field, MIME type set appropriately (I've tried BMP, JPG and GIF formats).

    Nothing displays whatsoever on the column, not even a red x.  I know data is being passed back, and I am able to display these images on other pages of the web application.

    I have also searched the forums extensively, and none of the proposed solutions has worked, and there are a few that I can't even see how to implement (mostly dealing with custom code).

    Any insight would be greatly appreciated.

    Thanks!

    Thursday, August 11, 2011 2:51 PM

Answers

  • OK, I figured out my problem, though I'm not sure of the root cause.  I think it's due to the fact that I was using a LINQ call to a stored procedure to pass the data.  Here's what I did, in case anyone else runs into this issue:

    1) I have a stored procedure where one of the returned columns is type IMAGE.
    2) When using the default (auto-generated) return type in a LINQ call, the image would not display.
    3) I created a class in the LINQ context to mirror the return set of the stored procedure (ItemHistoryResults).
    4) In that class, the type of the field for the image is Byte[].
    5) I set the return type of the stored procedure call to ItemHistoryResults.
    6) In code, I call the stored proc like this:
         List<ItemHistoryResults> x = context.usr_ItemHistory().ToList<ItemHistoryResults>();

    7) Pass the list x as the datasource for the report.
    8) In the Image object on the report, I simply set the image source to database and select the field that returns the byte[] field.  The MIME type apparently doesn't matter.

    I am assuming that the root cause of the problem is the way the image was returned from a stored procedure call, but I'm not positive.  Hopefully this will help someone who comes across something similar.

     

    • Marked as answer by Steve O2 Thursday, December 22, 2011 6:36 PM
    Thursday, December 22, 2011 6:36 PM

All replies

  • Wow, nothing on this?
    Tuesday, December 20, 2011 7:25 PM
  • Hi,

    Does image data stored in binary format in database or just a path of Image?

    When you give source = database then image data has to be in binary format.


    Regards,

    Asim Bagwan

    Kindly mark the replies as Answers if they help!

    Wednesday, December 21, 2011 7:03 AM
  • The image is stored in the database in a field of type IMAGE.  I have tried several methods, and none of them has worked.  I have tried using a field of type VARBINARY(MAX).  I have tried using custom code to convert from image to byte array. I have tried just using the field for the column.  I have tried using an image with an expression.  I have used every MIME type selectable.  Nothing shows up, not even a red x.

    It is a BMP format saved to the database.  I have no idea if it's the way I'm saving it, but I do know that these bitmaps will show properly on a datagrid.

    Wednesday, December 21, 2011 3:37 PM
  • As a followup, I have tried these two methods which I have seen suggested.  I have a Custom Code area in the report that has the following (and this is the entire file):

    Public  Function ByteToImage(img() As Byte) As System.Drawing.Image
       Dim objImage As System.Drawing.Image
       Dim bytImageBuffer() As Byte
       Dim objMemoryStream As System.IO. MemoryStream
     
       bytImageBuffer = img
       objMemoryStream = New System.IO.MemoryStream(bytImageBuffer, True)
       objMemoryStream.Write(bytImageBuffer, 0, bytImageBuffer.Length)
       objImage =System.Drawing.Image.FromStream(objMemoryStream)
       ByteToImage= objImage
    End Function

    Public  Function ImageToByte(BM As System.Drawing.Image) As Byte()
       Dim mystream As System.IO.MemoryStream = New System.IO.MemoryStream
       BM.Save(mystream, System.Drawing.Imaging.ImageFormat.Bmp)
       ImageToByte = mystream.ToArray()
    End Function

    I put an image object in the tablix field.  Go to properties, set Source to database. MIME type seems to have no effect (I've tried em all)

    For "Use This Field:", I have tried

    1) Fields!Signature.Value
    2) Code.ImageToByte(Fields!Signature.Value)
    3) Code.ByteToImage(Fields!Signature.Value)

    I have also tried the same with Fields!BinSig.Value, the VARBINARY field (Signature is an IMAGE type field).

    Wednesday, December 21, 2011 4:16 PM
  • OK, I figured out my problem, though I'm not sure of the root cause.  I think it's due to the fact that I was using a LINQ call to a stored procedure to pass the data.  Here's what I did, in case anyone else runs into this issue:

    1) I have a stored procedure where one of the returned columns is type IMAGE.
    2) When using the default (auto-generated) return type in a LINQ call, the image would not display.
    3) I created a class in the LINQ context to mirror the return set of the stored procedure (ItemHistoryResults).
    4) In that class, the type of the field for the image is Byte[].
    5) I set the return type of the stored procedure call to ItemHistoryResults.
    6) In code, I call the stored proc like this:
         List<ItemHistoryResults> x = context.usr_ItemHistory().ToList<ItemHistoryResults>();

    7) Pass the list x as the datasource for the report.
    8) In the Image object on the report, I simply set the image source to database and select the field that returns the byte[] field.  The MIME type apparently doesn't matter.

    I am assuming that the root cause of the problem is the way the image was returned from a stored procedure call, but I'm not positive.  Hopefully this will help someone who comes across something similar.

     

    • Marked as answer by Steve O2 Thursday, December 22, 2011 6:36 PM
    Thursday, December 22, 2011 6:36 PM