Link to home
Start Free TrialLog in
Avatar of ljhodgett
ljhodgett

asked on

Set crystal report image at runtime in vb.net

Hi Experts,

I have the following code: -

Imports System.Windows
Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
    Dim rpt As New CrystalReport1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As Integer
        Dim imageData() As Byte

        Dim ds As New InvoiceDataSet
        Dim imagepath As String = "c:\test.gif"
        Dim fi As New System.IO.FileInfo(imagepath)
        Dim imgstream As System.IO.Stream = fi.OpenRead
        x = CType(imgstream.Length, Integer)
        ReDim Preserve imageData(x)
        x = CType(fi.Length, Integer)
        imgstream.Read(imageData, 0, x)
        ds.DataTable1.AddDataTable1Row(imageData)

        rpt.Load(Forms.Application.StartupPath & "\crystalreport1.rpt")
        rpt.SetDataSource(InvoiceDataSet1.Tables(0))
        CrystalReportViewer1.ReportSource = rpt
    End Sub
End Class

What I am trying to do is place an image onto a crystal report using vb.net 2005 with the in built crystal report function. My problem is that when I place the array into the dataset the datagrid viewer that I have set to view what’s in the dataset it always shows a red x almost like internet explorer when the image can not be found. I have set the dataset field to byte(). What am I doing wrong please?

Many Thanks
Lee
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

Glad i could help

mlmcc