将参数传递给Crystal Report具有无效索引

时间:2011-01-11 09:03:49

标签: asp.net crystal-reports

下面的代码可以显示正确的报告, 但会有错误消息无效索引

如果我评论RD.SetParameterValue(“@ Transaction_date_field”,Calendar1.SelectedDate.ToShortDateString()); ,它不会有错误,但无法显示报告。

如何解决?

try
        {
            RD = new ReportDocument();
            RD.Load(@"D:\Data\My Documents\Visual Studio 2008\WebSites\Carpark\Daily_CrystalReport.rpt");
            //RD.Load(@".\Daily_CrystalReport.rpt");


            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = Calendar1.SelectedDate.ToShortDateString();
            crParameterFieldDefinitions = RD.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["Transaction_date_field"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            DailyReport_CrystalReportViewer.ReportSource = RD;

            RD.SetParameterValue("@Transaction_date_field", Calendar1.SelectedDate.ToShortDateString());
            DailyReport_CrystalReportViewer.EnableParameterPrompt = false;

            DailyReport_CrystalReportViewer.RefreshReport();
            //RD.Dispose();
        }
        catch (Exception ex)
        {
            Error_Label.Text = Error_Label.Text + " " + ex.Message;
            //Error_Label.Text = "";
        }

1 个答案:

答案 0 :(得分:0)

CrystalReport002,

我认为您可以使用以下内容将参数传递给报告:

var value = new ParameterDiscreteValue();
value.Value = Calendar1.SelectedDate.ToShortDateString();
RD.ParameterFields["Transaction_date_field"].CurrentValues.Add(value);