0
下面的代碼可以顯示正確的報道, 反而會產生錯誤信息無效指數參數傳遞給水晶報表具有無效指數
如果我評論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 = "";
}
我有這麼多的問題與水晶的工作,我定義了默認的方式來處理用它。如果你感興趣,你可以在這裏查看:http://tiagoontech.wordpress.com/2011/01/12/working-with-crystal-reports-and-c/ – 2011-01-12 19:33:34