troubleshooting Question

How do I dynamically load an image into Crystal Report using

Avatar of Programgod
Programgod asked on
Visual Basic.NETProgramming
16 Comments1 Solution1296 ViewsLast Modified:
I have been searching the web for an answer to my issue.  I have found many articles and forums, which I have used to get where I am, that discuss how to dynamically load images into a Crystal Report using VB.Net.  I have followed the examples to the letter and yet I am unable to get my images onto the report.  I have seen several peoples comments saying that it worked perfectly and that they were able to get it to work.  However, when I run my code and it gets to the point where it tries to read the bytes of the file into the row I get an exception error that states "Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.Couldn't store <System.Byte[]> in img Column.  Expected type is Byte."  I am not sure what I am doing wrong, but it does not seem to want to load.  Any assistance would be GREATLY appreciated.
Public Function ImgTable(ByVal ImageFile As String) As DataTable
        ImgTable = New DataTable
        Dim row As DataRow
        ImgTable.TableName = "Images"
        ImgTable.Columns.Add("img", GetType(System.Byte))
        FileCopy(ImageFile, "C:\test.tif")     '<-- I am only copying the image locally because of a different error
        Dim fs As New IO.FileStream("C:\test.tif", IO.FileMode.Open)
        Dim br As New IO.BinaryReader(fs)
        row = ImgTable.NewRow
        row(0) = br.ReadBytes(br.BaseStream.Length)   '<-- This is where I get the error
        br = Nothing
        fs = Nothing
    End Function

Open in new window

Éric Moreau
Senior .Net Consultant
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros