PPCC
Oct 7th, 2003, 06:03 AM
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
vbud
Oct 19th, 2004, 02:31 AM
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.
vbud
Oct 21st, 2004, 01:19 AM
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:
Public Sub AddImageColumn(ByVal objDataTable As DataTable, ByVal strFieldName As String)
Try
'create the column to hold the binary image
Dim objDataColumn As DataColumn = New DataColumn(strFieldName, Type.GetType("System.Byte[]"))
objDataTable .Columns.Add(objDataColumn )
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
'*... and this one to load the image in the above added field:
Public Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
Try
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
objDataRow (strImageField) = Image
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
'* 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.