Generate a Crystal Report with a Parameter

P

Philluminati

I have a crystal report which I need my application to generate. I can
do it like this:

ReportDocument thisReport = new ReportDocument();
thisReport.Load(inFilename);
thisReport.Refresh();
thisReport.ExportToDisk(ExportFormatType.PortableDocFormat,outputFilename);
thisReport.Close();

This works perfectly. Now I have a crystal report that takes a
parameter called "FirewallId". I have tried to make the code like
this:

ReportDocument thisReport = new ReportDocument();
thisReport.Load(inFilename);
thisReport.SetParameterValue("FirewallId",25);
thisReport.Refresh();
thisReport.ExportToDisk(ExportFormatType.PortableDocFormat,outputFilename);
thisReport.Close();

but I get missing parameter value. When I inspect "thisReports" fields
I am told there are two *more* parameters both called intid. Setting
them gives me errors - You cannot set parameters on linked fields and
not setting them gives me missing parameters error.

Can anyone help me please?
 
M

Mel Weaver

Try something like this, to see all the Parameter fields, and then just set
them

foreach (ParameterField field in thisReport.ParameterFields)
{
MessageBox.Show(field.Name);
thisReport.SetParameterValue(field.Name,"whatevervalue");
}
 
I

Ignacio Machin ( .NET/ C# MVP )

I have a crystal report which I need my application to generate. I can
do it like this:

ReportDocument thisReport = new ReportDocument();
thisReport.Load(inFilename);
thisReport.Refresh();
thisReport.ExportToDisk(ExportFormatType.PortableDocFormat,outputFilename);
thisReport.Close();

This works perfectly. Now I have a crystal report that takes a
parameter called "FirewallId". I have tried to make the code like
this:

ReportDocument thisReport = new ReportDocument();
thisReport.Load(inFilename);
thisReport.SetParameterValue("FirewallId",25);
thisReport.Refresh();
thisReport.ExportToDisk(ExportFormatType.PortableDocFormat,outputFilename);
thisReport.Close();

but I get missing parameter value. When I inspect "thisReports" fields
I am told there are two *more* parameters both called intid. Setting
them gives me errors - You cannot set parameters on linked fields and
not setting them gives me missing parameters error.

Can anyone help me please?

Hi,

you use ReportDocument.SetParameterValue()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top