我在报告中添加公式字段区域,从日期,到日期
即 更新的图像
我也尝试了另一种方法:
protected void Report_Click(object sender, EventArgs e)
{
data crystalReport = new data();
crystalReport.DataDefinition.FormulaFields["region"].Text = regiondrop.SelectedValue;
crystalReport.DataDefinition.FormulaFields["fromdate"].Text = fromdate.Value;
crystalReport.DataDefinition.FormulaFields["todate"].Text = todate.Value;
BindReport(crystalReport,Convert.ToDateTime(fromdate.Value), Convert.ToDateTime(todate.Value), regiondrop.SelectedValue);
}
这在页面上显示错误:
错误
此字段名称未知。详细信息:文件 temp_2c6994eb-49ef-432f-bfd7-af0eb80dc7ec 4032_6896_{5E54477E-F078-41DF-BD52-AF042B96DA53}.rpt 中的 errorKind 错误:公式 fromdate 中的错误:'{DataTable1.StartDate}' 此字段名称未知。详细信息:错误种类
现在这终于在@Furtiro 的帮助下工作了
public void BindReport(ReportDocument crystalReport, DateTime fromdate, DateTime todate, string region)
{
T1 t = new T1();
DateTime fdate = new DateTime(fromdate.Year, fromdate.Month, fromdate.Day, 0, 0, 0);
DateTime tdate = new DateTime(todate.Year, todate.Month, todate.Day, 23, 59, 59);
List<griddataresult_Result> dsc = t.griddataresult(fdate, tdate, region).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("OwnerName", typeof(string));
dt.Columns.Add("RegNo", typeof(string));
foreach (var c in dsc)
{
dt.Rows.Add(c.ID, c.OwnerName, c.RegNo, c.total_voilatio, c.MileageAccumlation, c.MaxSpeed);
}
crystalReport.DataDefinition.FormulaFields["region"].Text = "'" + region + "'";
crystalReport.DataDefinition.FormulaFields["fromdate"].Text = "'" + fromdate + "'";
crystalReport.DataDefinition.FormulaFields["todate"].Text = "'" + todate + "'";
crystalReport.SetDataSource(dt);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.DataBind();
}