0

我在 C# ASP.Net 中创建报告,在报告中我可以过滤在两个不同日期(例如开始日期:7 月 15 日和结束日期:7 月 17 日)之间创建的数据,但是在过滤特定日期创建的数据时(例如开始日期:7 月 15 日和结束日期:7 月 15 日)查询没有检索到任何内容...

//Code from OutletDistributor.aspx.cs
ReportManager master = ObjectFactory.GetInstance<ReportManager>();
ReportResponse responce = new ReportResponse();
if (ddDistributor == Guid.Empty)
  responce = master.GetAllOutletDistributor(sDate, EDate);
else
  responce = master.GetOutletDistributor(sDate, EDate, ddDistributor);
ReportViewer1.Reset();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
var stream = Assembly.GetAssembly(typeof(SampleReport)).GetManifestResourceStream(responce.ReportResource);
ReportDataSource reportDataSource = new ReportDataSource(responce.ReportDataSet, responce.ReportDataSource);
stream = RdlcReportHelper.TranslateReport(stream);
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.LoadReportDefinition(stream);
ReportViewer1.LocalReport.DisplayName = ResourceHelper.GetText(null, "hq.rpt.outletdist.heading");
ReportViewer1.LocalReport.Refresh();

//Code from ReportManager.cs
//Filter All Outlet Distributor
public ReportResponse GetAllOutletDistributor(DateTime StartDate, DateTime EndDate) {
  ReportResponse report = new ReportResponse();
  report.ReportResource = "Distributr.HQ.Lib.Reports.RcdlFiles.OutletDistributor.rdlc";
  List<OutletReportItem> Report = _outletReport.GetAllOutlets()
    .Where(p => p.CreationDate >= StartDate && p.CreationDate <= EndDate).ToList();
  Report.ForEach(n => report.ReportDataSource.Add(n));
  report.ReportDataSet = "dsOutletDistributor";
  return report;
}
4

3 回答 3

1

我假设StartDate两者EndDate都包含时间组件。Date使用属性删除它:

StartDate = StartDate.Date;
EndDate = EndDate.Date;

// your query goes here...
于 2012-07-26T09:58:30.937 回答
0

In this condition where your date is same use "=" (instead of difference) in your query

于 2012-07-26T10:02:43.997 回答
0

实际上,您的代码List<OutletReportItem> Report = _outletReport.GetAllOutlets().Where(p => p.CreationDate >= StartDate && p.CreationDate <= EndDate).ToList()在初始化对象 DateTime 时,日期的默认值是小时、分钟和秒,它们是“00”。所以我认为你可以使用 DateTime.Compare()

于 2012-07-26T10:09:19.553 回答