Crystal报表在报表加载时显示参数提示。
加载报告的我的代码是: -
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"];
logOnInfo.ConnectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DBName"];
logOnInfo.ConnectionInfo.IntegratedSecurity = false;
logOnInfo.ConnectionInfo.UserID = System.Configuration.ConfigurationManager.AppSettings["UID"];
logOnInfo.ConnectionInfo.Password = System.Configuration.ConfigurationManager.AppSettings["PWD"];
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in SchoolExpenseReport.ReportDocument.Database.Tables)
tbl.ApplyLogOnInfo(logOnInfo);
ParameterValues pvSchoolExpense = new ParameterValues();
ParameterDiscreteValue pdvFomDate = new ParameterDiscreteValue();
ParameterDiscreteValue pdvToDate = new ParameterDiscreteValue();
pdvFomDate.Value = txtFromDate.Text;
pdvToDate.Value = txtToDate.Text;
SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["FromDate"].CurrentValues.Clear();
pvSchoolExpense.Add(pdvFomDate);
SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["FromDate"].ApplyCurrentValues(pvSchoolExpense);
SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["ToDate"].CurrentValues.Clear();
pvSchoolExpense.Add(pdvToDate);
SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["ToDate"].ApplyCurrentValues(pvSchoolExpense);
SchoolExpenseReportViewer.ReportSource = SchoolExpenseReport;
SchoolExpenseReportViewer.DataBind();
SchoolExpenseReportViewer.RefreshReport();
SchoolExpenseReport.Visible = true;
显示参数提示,如下所示
答案 0 :(得分:0)
我不太熟悉添加这样的参数。我通常使用.SetParameterValue()
。
当我将日期设置为参数值时,它们通常采用DateTime
格式,但我看到您只是分配字符串值。
尝试更改此内容:
pdvFomDate.Value = txtFromDate.Text;
pdvToDate.Value = txtToDate.Text;
对此(根据TextBox
中的日期更改格式字符串):
pdvFomDate.Value = DateTime.ParseExact(txtFromDate.Text, "MM/dd/yyyy");
pdvToDate.Value = DateTime.ParseExact(txtToDate.Text, "MM/dd/yyyy");
FWIW,我考虑使用日期选择器控件而不是文本框来接受用户的日期值。
如果这不起作用,请尝试使用此备用语法来设置参数值:
var fromDate = DateTime.ParseExact(txtFromDate.Text, "MM/dd/yyyy");
SchoolExpenseReport.ReportDocument.SetParameterValue("FromDate", fromDate);