How to pass parameters to Crystal Report for Visual Studio 2010? Looks like they are ignored

mattruma picture mattruma · Nov 17, 2010 · Viewed 7.9k times · Source

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}

Answer

mattruma picture mattruma · Mar 27, 2012

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