views:

162

answers:

2

Hello, 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

A: 

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.

Jeremy Bell
A: 

You don't need a Data Table for a crystal report but you will need an rpt file. Instead of populating the Data Table you can use your stored procedure as the data source for your crystal report. The easiest way to set the datasource to the stored procedure is in the .rpt file. In Visual Studio Under Crystal Reports ->Database->Database Expert, then select your database and the stored procedure you wish to use as a data source.

Jeff Schmidt
How do I set the data source to be a stored proc?
Frank