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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With