Extracting a database binary to an RDLC Image field

Answered Extracting a database binary to an RDLC Image field

  • 25 Februari 2010 23:15
     
     

    Continuing my research into implementing RDLC reports.  One functionality we require is displaying inventory
    images on the report. This will be a VB.net 2005 app running on workstations. A simplified environment has been
    staged by adding and populating an image field in The Northwind Customers table. An extraction function 
    was tested successfully on a winform app populating a picturebox.  My sticking point is that there is not an
    "Expression" context menu for an image control.  The "Data Region" combobox doesn’t seem right.
    The function references only Row 2 for now, because I'm not used to working with bound controls
    and don't know how to reference the current record. Any help is much appreciated !

    Found this so far: http://msdn.microsoft.com/en-us/library/ms251715(VS.80).aspx

    http://i286.photobucket.com/albums/ll84/gto866/Dev/RDLC2.jpg

    Imports Microsoft.Reporting.WinForms
    Imports System.IO
    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.CustomersTableAdapter.Fill(Me.northwndDataSet.Customers)
    Me.ReportViewer1.LocalReport.EnableExternalImages = True
    Me.ReportViewer1.RefreshReport()
    End Sub

    Private Function ByteToImage() As Image

    Dim objImage As Image
    Dim bytImageBuffer() As Byte
    Dim objMemoryStream As MemoryStream

    bytImageBuffer = Me.northwndDataSet.Tables(0).Rows(2).Item("ImagePicture")
    objMemoryStream = New MemoryStream(bytImageBuffer, True)
    objMemoryStream.Write(bytImageBuffer, 0, bytImageBuffer.Length)
    objImage = Image.FromStream(objMemoryStream)
    ByteToImage = objImage
    End Function
    End Class

    Update:

    After reading about the CODE global variable, I tried this:
    Go to the Report->Properties menu
    Click the Code tab and define the function.
    Click the Element tab. enter      Image1
    Click the Data Output tab and enter      =Code.ByteToImage(Fields!ImagePicture.value))

    This is possibly moving in the right direction, but still errors out with
    "Value expression for image1 is an empty string"

    http://i286.photobucket.com/albums/ll84/gto866/Dev/RDLC3.jpg


    Update:
    To eliminate dataset problems, replaced expression with a simple function to
    return a bitmap from file. Still errors out with the empty string message

Semua Balasan

  • 26 Februari 2010 19:17
     
     
    Have you tried just binding to the byte array instead of the Image?
  • 26 Februari 2010 20:01
     
     Jawab
    It worked !

    http://i286.photobucket.com/albums/ll84/gto866/RDLC4.jpg

    A couple of my searches showed somewhat similar requests and the response was a write a custom expression.
    So  .Net handles this natively. Very nice.


    Thanks,
    Steve 

     

     

     

    PS.

    Actually it was on MSDN where I saw this
    http://msdn.microsoft.com/en-us/library/ms251715.aspx

    Using an External or Database Image to a Report

    To use a database image, you can specify the database field that contains the image as long as the MIME type is JPG, PNG, or BMP. If the image is stored as a binary object, you must write an expression that converts the image to a supported type.

     

  • 18 April 2012 15:49
     
     
    Uhh...and the custom expression was??
  • 07 Desember 2012 14:25
     
     
    There's no need for the custom expression. Just binding the byte array works.