Link to home
Start Free TrialLog in
Avatar of yireh
yireh

asked on

DYNAMIC IMAGE TO CRYSTAL REPORTS

I have the following code but the image is not showing in the report.

    Private mdsData As DataSet
    Private mrptDoc As New ReportDocument

    Private Sub CreateDataSet()
        mdsData = New DataSet("CardData")

        Using dt As New DataTable("CardData")
            dt.Columns.Add("Foto", System.Type.GetType("System.Byte[]"))
            dt.Columns.Add("FullName", GetType(String))
            dt.Columns.Add("NumSocio", GetType(String))
            dt.Columns.Add("TipoSocio", GetType(String))
            dt.Columns.Add("SinceDate", GetType(String))

            'Save the canadian flag into a Memory Stream object
            'and from there to an array of byte

            Dim fs As New FileStream("l:\pr.gif", FileMode.Open)   ' create a file stream
            Dim br As New BinaryReader(fs)                      ' create binary reader
            Dim row As DataRow

            ' create a new datarow
            row = dt.NewRow()

            ' set country field and image field
            row("Foto") = br.ReadBytes(br.BaseStream.Length)
            row("FullName") = "John Doe"
            row("NumSocio") = "123456"
            row("TipoSocio") = "ELITE"
            row("SinceDate") = "2/01/2002"

            ' add this row to the table
            dt.Rows.Add(row)

            ' clean up
            br = Nothing
            fs = Nothing

            mdsData.Tables.Add(dt)
        End Using

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        CreateDataSet()
        mdsData.WriteXmlSchema(My.Computer.FileSystem.SpecialDirectories.Temp & "\CardData.xsd")
        'Load the standalone report
        mrptDoc.Load("C:\cfass\bin\Debug\reportes\rptCard.rpt")

        'Pass the dataset to the report
        mrptDoc.SetDataSource(mdsData)

        'Set the values of the parameters
        mrptDoc.SetParameterValue("BarCodeNumber", "123456")
        mrptDoc.SetParameterValue("ClubName", "CURRENT CLUB")

        'Pass the Report Document object to the viewer
        CrystalReportViewer1.ReportSource = mrptDoc
    End Sub
Avatar of riyazthad
riyazthad

I think you need to use typed dataset and crystal report dynamic chat. I hope this may help you.

http://www.thescripts.com/forum/thread103039.html

Thad
Avatar of Éric Moreau
try with a bitmap first (before trying a GIF). not all image formats are available.
Avatar of yireh

ASKER

No, the .bmp is not working.
have you tried the sample I have in my article of October 2006 from http://emoreau.s2i.com/ ?
Avatar of yireh

ASKER

Eric, looking your sample. Your report have the image in IBlobFieldObject and my report have the image in a IFieldObject but not have the option to change the object type.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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 yireh

ASKER

Yes,

It's working. The problem is with the schema.

Thnaks Eric.