【问题标题】:How to pass parameters to Crystal Report for Visual Studio 2010? Looks like they are ignored如何将参数传递给 Visual Studio 2010 的 Crystal Report?看起来他们被忽略了
【发布时间】:2010-11-17 14:46:18
【问题描述】:

这在 Visual Studio 2008 中工作正常,但由于我已切换到 Visual Studio 2010 和适用于 Visual Studio 2010 的 Crystal Reports,我传递的参数被忽略。

它们显示在报告中,只是在涉及选择公式时被忽略!这是我创建报告和传递参数的代码。

 private void Prepare()
    {
        var reportDocument = new ReportDocument();

        string reportPath = string.Format(
            "{0}\\{1}",
            Globals.FormPath,
            this.FormTemplate.Filename);

        reportDocument.Load(reportPath);

        ParameterDiscreteValue parameter;

        foreach (var control in this.FormTemplateFieldControls)
        {
            switch (control.FormTemplateField.DataType)
            {
                case FormFieldDataType.Date:
                    this.AddParameterForDateTime(
                        reportDocument,
                        control.FormTemplateField.Name,
                        (DateTime)control.EditValue);
                    break;
                case FormFieldDataType.DateTime:
                    this.AddParameterForDateTime(
                        reportDocument,
                        control.FormTemplateField.Name,
                        (DateTime)control.EditValue);
                    break;
                case FormFieldDataType.Time:
                    this.AddParameterForDateTime(
                        reportDocument,
                        control.FormTemplateField.Name,
                        (DateTime)control.EditValue);
                    break;
                case FormFieldDataType.Guid:
                    this.AddParameterForGuid(
                        reportDocument,
                        control.FormTemplateField.Name,
                        (Guid)control.EditValue);
                    break;
                default:
                    this.AddParameterForString(
                        reportDocument,
                        control.FormTemplateField.Name,
                        control.EditValue.ToString());
                    break;
            }
        }

        this.SetConnectionInfo(reportDocument);

        var frm = new FormViewer();

        frm.Report = reportDocument;

        frm.ShowDialog();

        frm.Dispose();

        this.Close();
    }

当我从设计器运行报告时,它工作得很好。当我在报告中显示参数时,您可以看到正在传递的参数。

对于我从存储过程运行的报告,参数似乎可以通过,它只是由所有表组成的那些。

对于它的价值,这是我的选择公式:

 {employee.HireDate} >= {?StartDate} And {employee.HireDate} <= {?EndDate}

【问题讨论】:

  • 即使我只是尝试让 Crystal Reports 提示他们没有传递的参数。
  • 真正奇怪的是,如果我单步执行代码,并在运行时查看参数的值,它会正确显示。
  • 所以我将我的报告切换为使用存储过程并且它工作了......但我不应该这样做......呃!
  • 我也有同样的问题。我有一个访问视图的报告,传入的参数应该识别视图中的一条记录,这就是报告显示的内容。据我所知,参数正在正确传递。我可以在报告中显示它。但是,视图没有过滤参数,这是我在 VS2005 中运行它时所做的。我使用 Profiler 确认了这一点。 VS2005 在查询中添加了 where 子句,而 2010 则没有。我尝试更改参数名称并重做记录选择,但没有成功。 T
  • @Neil 我们最终只是使用 VS 2008 创建了一个引用旧 CR 程序集的网站,然后让我们使用 VS 2010 编写的 Windows/Web 应用程序将所有报告发送到该网站。这很 hackish,但它有效。

标签: c# visual-studio-2010 crystal-reports crystal-reports-2010


【解决方案1】:

最新版本的 Crystal Reports for Visual Studio 2010 已解决此问题。

【讨论】:

    【解决方案2】:

    当您说“他们没有通过”时,会通过什么?它们是空白的吗?

    您可以自己查看参数,只是为了笑,尝试给它们起一个不同的名称,一些更加独特的名称。其他一些报告设置或参数的定义方式可能会出现问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多