passing parameter to Crystal Report have invalid index
Below code can display a correct report, but will have error message invalid index
if i comment RD.SetParameterValue("@Transaction_date_field", Calendar1.SelectedDate.ToShortDateString()); , it will not have error, but can not show report.
How to fix it?
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();
crParameterFie开发者_StackOverflow中文版ldDefinitions = 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 = "";
}
CrystalReport002,
I think you could pass the parameters to report using something like this:
var value = new ParameterDiscreteValue();
value.Value = Calendar1.SelectedDate.ToShortDateString();
RD.ParameterFields["Transaction_date_field"].CurrentValues.Add(value);
精彩评论