C# 在 Crystal Reports 中为参数分配多个值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/840085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Assign multiple values to a parameter in Crystal Reports
提问by Nathan Koop
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.
这是一个状态列(IE、Proposed、In Progress、Completed、Canceled),我希望用户能够选择报告哪些(以及多少)不同的 OrderStatus。
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.
我检查过它确实将值添加到 OrderStatus 参数,但是当报表运行时,CrystalReports 对话框会弹出并要求我输入 OrderStatus 参数的值。因此,这些值似乎并未“提交”给参数。我已经进行了多次搜索,但无法弄清楚为什么它不起作用。
Thanks,
谢谢,
采纳答案by dotjoe
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 inoperator.
在选择专家中,您将使用in运算符。
{table.order_status_id} in {?@OrderStatus}
回答by Rich.Carpenter
Have you set the parameter to Hidden in the Crystal Reports parameter options?
您是否在 Crystal Reports 参数选项中将参数设置为隐藏?
回答by Dusty
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.
我还没有尝试过,但我认为您应该能够将 intOrderStatus 添加到 ParameterDiscreteValue 或 ParameterRangeValue 并将其传递到 Parameter_OrderStatus.CurrentValues 而不是 intOrderStatus。
回答by Mohammed Atif Sami
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
你可以做的是,制作一个普通的参数字段,即没有多个值,只有谨慎的值是真的,你需要传递的是1、2、3、4。"," 是分隔符,使用您认为对您有用的分隔符,然后在记录选择公式中简单地输入
{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
您需要从页面传递的是字符串 1,2,3,4 并且它应该可以工作
回答by Ali
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);
回答by Hossein Golshani
Following is tested in Crystal Reportsversion 13.0.20:
以下是在Crystal Reports版本13.0.20 中测试的:
1)In Parameter Fields
section add new parameter as follow:
1)在Parameter Fields
部分添加新参数如下:
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):
2)Select Expert Record ...
在Crystal Reports中选择,代码可能是这样的(使用=
运算符):
{Orders.OrderStatus} = {?ParamMultipleOrderStatus}
3)Use following code:
3)使用以下代码:
foreach (int intOrderStatus in intSelectedOrderStatuses)
{
report.ParameterFields["ParamMultipleOrderStatus"].CurrentValues.AddValue(intOrderStatus);
}