简体   繁体   English

在c#中将参数值设置/传递给Crystal报表不起作用

[英]Setting/Passing a Value to a Parameter to a Crystal Report in c# is Not Working

I have 2 parameters (Detail, Summary) that I have created in a Crystal Report. 我有两个在Crystal Report中创建的参数(详细信息,摘要)。 The report is called from c# in a Windows Forms application. 在Windows窗体应用程序中从c#调用该报告。 I am trying to pass the appropriate value to each parameter at runtime so the report can make some decisions based on the values. 我试图在运行时将适当的值传递给每个参数,以便报表可以基于这些值做出一些决策。 I have read many articles regarding this and I think I am using the best method to accomplish this? 我已经阅读了很多有关此的文章,我认为我正在使用最好的方法来完成此任务?

This is the simple code I have implemented after the report has been loaded and before the SetDataSoruce has been set: 这是我在加载报告之后和设置SetDataSoruce之前实现的简单代码:

crReportDocument.SetParameterValue("DetailView", false);
crReportDocument.SetParameterValue("SummaryView", true);

For some reason the values are not getting to the report as the report is always prompting for the values to be set when it runs. 由于某些原因,这些值未到达报告,因为报告始终在运行时提示您设置值。

Everything else about the report works correctly. 有关该报告的所有其他信息都可以正常运行。

I would appreciate any light someone can shed on this matter as it seems to be a simple task to do? 我希望有人能对此事提供任何启发,因为这似乎很简单?

The problem is that the parameter must be passed using format {?PARAMETER} . 问题是必须使用格式{?PARAMETER}传递{?PARAMETER} It works. 有用。

crReportDocument.SetParameterValue("{?DetailView}", false);

crReportDocument.SetParameterValue("{?SummaryView}", true);

Actually the problem was code placement. 实际上,问题出在代码放置。 I was populating the parameters in the wrong place of code execution: 我在错误的代码执行位置填充了参数:

This is how I had it when it was not working: 这是它在不起作用时的处理方式:

crReportDocument.SetParameterValue("FromDate", dtmFromDate);
ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;

To resolve I moved the code around as follows: 为了解决这个问题,我将代码移动如下:

ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;
crReportDocument.SetParameterValue("FromDate", dtmFromDate);

That's all it took to get it to work correctly. 这就是使其正常工作所需要的。 Let me know if it does not work for you. 让我知道它是否不适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM