如何向 Crystal Report for Visual Studio 2010 传递参数?看起来他们被忽略了

发布于 2024-10-03 11:16:10 字数 2502 浏览 7 评论 0原文

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

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

 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();
    }

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

alt text

对于我从存储过程运行的报告,参数似乎传递得很好,它只是由所有表组成的参数。

就其价值而言,这是我的选择公式:

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

This was working correctly in Visual Studio 2008, but since I have switch to Visual Studio 2010 and Crystal Reports for Visual Studio 2010, my passed parameters are ignored.

They display in the report, just ignored when it comes to the selection formula! Here is my code for creating the report and passing the parameters.

 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();
    }

When I run the report from the designer it works just fine. You can see the parameters are being passed as I am displaying them in my report.

alt text

For my reports that run from stored procedures the parameters seem to pass just fine, it's just the ones composed of all tables.

For what it's worth, here is my selection formula:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2024-10-10 11:16:10

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

This has been resolved with the latest version of Crystal Reports for Visual Studio 2010.

故笙诉离歌 2024-10-10 11:16:10

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

您可以自己检查参数,并且只是为了笑一下,尝试给它们起一个不同的名称,一些额外的独特名称。其他一些报告设置或参数定义方式可能会出现一些愚蠢的情况。

When you say "they don't get passed", what DOES get passed? Are they blank?

You might review the parameters themselves, and just for grins, try giving them a different name, something extra unique. There could be something goofy going on with some other report setting or the way the parameters are defined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文