Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a single collection to hold all parameters

I take user input on a form and bind it to a parameter which will then tie to my report. Can I use a single collection to hold all of my parameters? It seems redundant to have to create a collection and a parameter for every item I want to pass to my report.


To make this work the way I require, I've had to add a collection for each param on my form:

// #1 Setup a collections
    ParameterValues firstNameCollection = new ParameterValues();
    ParameterValues lastNameCollectoin = new ParameterValues();

Then I created the actual parameter:

// #2 Set the parameters
    ParameterDiscreteValue firstNameParam = new ParameterDiscreteValue();
    ParameterDiscreteValue lastNameParam = new ParameterDiscreteValue();

Bound the value:

// #3 Set the values
    firstNameParam.Value = "First Name";
    lastNameParam.Value = "Last Name";

Added the parameters to the collection:

// #4 Add the parameters to the collection
    firstNameCollection.Add(firstNameParam);
    lastNameCollectoin.Add(lastNameParam);

And applied the collections to the form:

// #5 Apply the collections to the report
    MyReport.DataDefinition.ParameterFields["FirstName"].ApplyCurrentValues(firstNameCollection);
    MyReport.DataDefinition.ParameterFields["LastName"].ApplyCurrentValues(lastNameCollectoin);
like image 601
Cody J. Mathis Avatar asked Aug 10 '16 20:08

Cody J. Mathis


1 Answers

The proper way to fill a Crystal Report Parameter in C#.

MyReport.SetParameterValue("NameOfReportParam", Object);

In the initial question, I was creating the parameter vs referencing it as shown here.

like image 158
Cody J. Mathis Avatar answered Oct 02 '22 10:10

Cody J. Mathis