Nathan Koop
Nathan Koop

Reputation: 25197

Assign multiple values to a parameter in Crystal Reports

I have added a parameter to my report with the option "Allow Multiple Values" checked.

This is a status column (IE, Proposed, In Progress, Completed, Canceled), and I want the user to be able to select which (and how many) different OrderStatus to report on.

How I normally set parameters is:

report.SetParameterValue("@dtBegin", dtBegin.DateTime);

What I tried to do for the multiple values was something like this:

//pseudo loop
foreach(int intOrderStatus in intSelectedOrderStatuses)
{
    report.Parameter_OrderStatus.CurrentValues.AddValue(intOrderStatus);
}

I have checked it does add the values to the OrderStatus parameter, but when the report runs, the CrystalReports dialog pops up and asks me to enter values for the OrderStatus parameter. So it seems as though the values aren't "commited" to the parameter. I have done a number of searches and can't figure out why it's not working.

Thanks,

Upvotes: 6

Views: 16370

Answers (6)

Hossein Golshani
Hossein Golshani

Reputation: 1897

Following is tested in Crystal Reports version 13.0.20:

1) In Parameter Fields section add new parameter as follow:

Name: ParamMultipleOrderStatus
Type: Number
Value Options: 
    Allow multiple values: true

2) Choose the Select Expert Record ... in Crystal Reports and code may like this (use = operator):

{Orders.OrderStatus} = {?ParamMultipleOrderStatus}

3) Use following code:

foreach (int intOrderStatus in intSelectedOrderStatuses)
{
    report.ParameterFields["ParamMultipleOrderStatus"].CurrentValues.AddValue(intOrderStatus);
}

Upvotes: 0

Ali
Ali

Reputation: 478

Well i have same issue. The work around is very simple. Don't add data source after parameters. e.g

report.SetParameterValue("@dtBegin", dtBegin.DateTime);
report.SetParameterValue("@dtBegin2", dtBegin.DateTime1);
//Note datasource is assigned after parameters
report.SetDatasource(dataset);

The crystal report will refresh parameters before applying data source to report. The below is the not popup discrete dialog box

//Note Datasource is applied before parameters
report.SetDatasource(dataset);
report.SetParameterValue("@dtBegin", dtBegin.DateTime);
report.SetParameterValue("@dtBegin2", dtBegin.DateTime1);

Upvotes: 0

Mohammed Atif Sami
Mohammed Atif Sami

Reputation: 11

What you can do is, make a normal parameter field,i.e without multiple values, only discreet values true, all you need to pass is 1,2,3,4. "," is the delimiter for separation use what ever you think works for you, then in record selection formula simply put

{table.order_status_id} in split({@OrderStatus}, ",")

all you need to pass from you page is the string 1,2,3,4 and it should work

Upvotes: 1

Dusty
Dusty

Reputation: 4707

I haven't tried this, but I think that you should be able to add intOrderStatus to either a ParameterDiscreteValue or ParameterRangeValue and pass that into Parameter_OrderStatus.CurrentValues instead of intOrderStatus.

Upvotes: 0

dotjoe
dotjoe

Reputation: 26940

Just set the parameter value with an array of ints.

report.SetParameterValue("@OrderStatus", new int[]{1,2,3});

in the select expert you would use the in operator.

{table.order_status_id} in {?@OrderStatus}

Upvotes: 10

Rich.Carpenter
Rich.Carpenter

Reputation: 1066

Have you set the parameter to Hidden in the Crystal Reports parameter options?

Upvotes: 0

Related Questions