Results 1 to 3 of 3

Thread: displaying image in crystal report

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Cool displaying image in crystal report

    Have u worked on Crystal reports
    How do i display a image from the database (Either image path or binary value data)on the crystal report.

    tell me if u know.Thanks in advance.

    Help expected

    PPCC

  2. #2
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    Well this thread has not been solved yet and I'm having the same problem, does anybody has any clue on how to get this done?

    All help appreciated, thanx.
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

  3. #3
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378

    got it

    I actually got this solved finally and I think it might be useful to post it. So here it goes:

    In my table in SQL I have the path to an image that needs to be displayed in a crystal report document.

    First of all, I created a new Dataset/XML schema(xsd) in VS.Net that maps the fields that I have in my table. This should be the normal procedure when creating a report I guess. Now, in this DataSet i've added an additional field that is not in the table and which is of type base64Binary :

    <xs:element name="Image" type="xs:base64Binary" minOccurs="0" />

    Now I designed my report based on this DataSet and included the "Image" field in the region where I want it to appear. In my case it was the report header.

    Once this is done, in my VB.net coding, I retrieved the data that needs to be diplayed on the report from the database through a DataSet.
    Then I used this code to add the extra field to hold the image:
    VB Code:
    1. Public Sub AddImageColumn(ByVal objDataTable As DataTable, ByVal strFieldName As String)
    2.     Try
    3.       'create the column to hold the binary image
    4.       Dim objDataColumn As DataColumn = New DataColumn(strFieldName, Type.GetType("System.Byte[]"))
    5.     objDataTable .Columns.Add(objDataColumn )
    6.     Catch ex As Exception
    7.       Throw New Exception(ex.Message)
    8.     End Try
    9.   End Sub
    10.  
    11. '*... and this one to load the image in the above added field:
    12.  
    13.   Public Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
    14.     Try
    15.       Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
    16.       Dim Image() As Byte = New Byte(fs.Length) {}
    17.       fs.Read(Image, 0, CType(fs.Length, Integer))
    18.       fs.Close()
    19.     objDataRow (strImageField) = Image
    20.     Catch ex As Exception
    21.       Throw New Exception(ex.Message)
    22.     End Try
    23.   End Sub
    24.  
    25. '* then bind the report to the dataset using the SetDataSource method and there you should get it.

    Actually I faced another issue, I tried to load an image of type wmf but it would not accept it and was raising some error so I was able to load a jpg image on the report without struggling any further. hope this helps for all those who have been trying to do this.
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width