Search code examples
c#asp.netoracleplsqlcrystal-reports

Generate Crystal Report 'on the fly'


I'm doing an Asp.Net application which will, eventually, generate 'on the fly' report with parameters entered by the user. I'm trying to understand how to dynamically generate Crystal Report reports.

Actually, I've got a stored proc being called and filling a DataTable with the results. But there is one part missing to my problem.

How do I populate the CrystalReportViewer with the DataTable?

I suppose I have to create a .rpt file and populate it, but isn't that useless code repetition?

Thank you


Solution

  • This isn't exactly what you are looking for... but this is a code snippet that we use to generate PDF copies of Crystal Reports on the fly.

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    
    Using rpt As New ReportDocument()
      With rpt
        .Load("/Path/To/RTPFile.rpt", OpenReportMethod.OpenReportByTempCopy)
        .SetDataSource(dataSource)
        .ExportToDisk(ExportFormatType.PortableDocFormat, "/Path/To/Report.pdf")
      End With
      rpt.Close()
    End Using
    

    In this case 'datasource' is an XSD Dataset that has been loaded with the report data ready-to-go.