Assign multiple values to a parameter in Crystal R

2019-04-29 19:25发布

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,

6条回答
Juvenile、少年°
2楼-- · 2019-04-29 19:29

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}
查看更多
何必那么认真
3楼-- · 2019-04-29 19:35

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);
}
查看更多
家丑人穷心不美
4楼-- · 2019-04-29 19:35

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);
查看更多
Lonely孤独者°
5楼-- · 2019-04-29 19:39

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

查看更多
狗以群分
6楼-- · 2019-04-29 19:46

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

查看更多
三岁会撩人
7楼-- · 2019-04-29 19:46

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.

查看更多
登录 后发表回答