Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add image to crystal report at runtime through VB.NET

Status
Not open for further replies.

dswitzer

Technical User
Aug 2, 2002
298
US
I'm using CRXI, VB2005, and an MSAccess database.

I have an issue with large images being visible in the report when run through crystal -- but when integrated into VB with the crviewer - they do not appear (no red x's -- just the border outline appears). What I'm wondering is if I can add the image at runtime through VB - I want to test this to see if this override will work and make the image visible.

Here is my code to view a crystal report (it is ugly as I had to cycle through the report and apply the logon info to every table in the report as well as every table in each subreport):
Code:
Public dbPath As String = "C:\CentralData.mdb"
Public rptPath As String = "C:\"
Public rptEastSpcl As String = rptPath + "specialPricing_East_1183v2.rpt"


'button uses this to show the report
Call showReport(rptEastSpcl)


 Private Sub showReport(ByVal rptName As String)
        Dim crReport As New ReportDocument
        Dim crTable As Table

        crReport.Load(rptName)
        'Step 1 cycle through main tables on report and set to hit db
        For Each crTable In crReport.Database.Tables
            crTable.Location = dbPath
        Next crTable

        Dim ci As New ConnectionInfo()
        Dim subObj As SubreportObject
        Dim obj As ReportObject

        ci.DatabaseName = dbPath

        For Each obj In crReport.ReportDefinition.ReportObjects
            If (obj.Kind = ReportObjectKind.SubreportObject) Then
                subObj = CType(obj, SubreportObject)

                If Not (ApplyLogon(crReport.OpenSubreport(subObj.SubreportName), ci)) Then
                    'These are the ones that hit the database
                    For Each crTable In crReport.OpenSubreport(subObj.SubreportName).Database.Tables
                        crTable.Location = dbPath
                    Next crTable
                End If
            End If
        Next

        frmVwrCustom.crViewer1.ReportSource = crReport
        frmVwrCustom.Show()

    End Sub

now, I found some code here where someone was putting an image into a table and then putting a report.datasource to the table. How can I integrate a table like this (code below) with what I have done above?

Code:
Dim data As New DataSet()
Dim row As DataRow

data.Tables.Add("Images")
data.Tables(0).Columns.Add("img", System.Type.GetType("System.Byte[]"))

Dim fs As New FileStream("C:\test.jpg", FileMode.Open)
Dim br As New BinaryReader(fs)

row = data.Tables(0).NewRow()
row(0) = br.ReadBytes(br.BaseStream.Length)
data.Tables(0).Rows.Add(row)

br.close
fs.close

br = Nothing
fs = Nothing

' CrystalReport1 is a strongly typed report created in Visual Studio.
Dim cr As New CrystalReport1()
cr.SetDataSource(data)
CrystalReportViewer1.ReportSource = cr

Thanks.
 
I'm not sure if VB2k5 has a different integrated CR module, but 2k2's integrated CR module was from version 9 of CR. You may want to try creating the report from scratch in the CR.Net environment and adding your images there first. XI and 9 arn't entirely compatible.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks for the suggestion. I sheepishly have to admit that I haven't tried this one yet. So, I tried it and received too many errors "unable to embed resource file...Not enough storage is available to complete the operation."

I use 8-10 images in each report (each image is about 24MB in bmp form) -- so the resulting report is around 210MB(without data) and VB has a hard time dealing with files that large -- that is why I create them in Crystal as standalone reports and then just display them through VB.

Other ideas? I'm looking for the windows app user to be able to preview the reports and then export to pdf -- the crviewer seems perfect for this, but if you can think of another way, I'm all ears.
 
If you have CR XI you have the CR XI royalty free report viewer. Drop the CR 9 references and merge modules out of your project and deployment. Then add the "CrystalDecisions.CrystalReports.Engine.dll", "CrystalDecisions.ReportSource.dll", "CrystalDecisions.Shared.dll", and "CrystalDecisions.windows.forms.dll" references then add "crystal11_net_embeddedreporting.msm" to your deployement package.

The CR11 deployment sucks. For some reason they decided that allowing developers to distribute just the required files wasn't a good idea, so we're stuck with the 75 meg merge file instead.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I finally got around this issue....

I load the images into datatables/merge into a single dataset, create an xml schema file. Then I can use the xml schema file as datasource for my report.

It was quite a bit of work -- but it does work and on the bright side -- I can now avoid the code to apply logon credentials to every subreport, and my report size is quite small (until it is run)....

Thanks for the help.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top