views:

962

answers:

2

Hi, I've been trying to get this to work for a while, and all the example code I've seen aren't quite doing what I'm doing.

I have a program that returns a pdf of a report that I pass a data table to. This works fine, except I would like to pass it a couple of other parameters (the date range of the table, stats etc) and I just can't get it to work. My code basically looks like this.

ReportDocument myDataReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
myDataReport.Load(@"C:\Layouts\Report.rpt");
ParameterField myParam = new ParameterField();
ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();
myParam.ParameterFieldName = "MyParameter";
myDiscreteValue.Value = "Hello";
myParam.CurrentValues.Add(myDiscreteValue);
myDataReport.ParameterFields.Add(myParam);
myDataReport.SetDataSource(myDataTable);
Stream returnData = myDataReport.ExportToStream(PortableDocFormat);
myDataReport.Close();
return returnData;

I have added the parameter field in the rpt document in crystal, do I have to change anything in the xsd file in c#, or am I missing something completely different?

Many thanks, Andy.

+1  A: 

All that parameter code can be replaced with...

myDataReport.SetParameterValue("MyParameter", "Hello");

I can't remember if the order matters when setting the datasource and parameters. Maybe try setting the datasource first. The xsd/datasource has no relation to crystal parameters.

dotjoe
Yep that was it! I think I tried that line before, but I had the datasource set in the wrong place as you pointed out. Works compeletly now, thanks!
Andrew Jones
@Andrew. Could you please tell me where did you put the call to the dataSource?
Unlimited071
Put SetParameterValue AFTER the datasource asignation
Apocatastasis