2012-07-26 454 views
0

我在C#ASP.Net中創建報表,在報表中我可以過濾兩個不同日期之間創建的數據(例如開始日期:7月15日和7月17日結束日期),但是當它談到在某一天創建過濾數據(如開始日期:7月15日和結束日期:7月15日)查詢不檢索任何東西......按日期和時間過濾C#

//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; 
} 

回答

1

我認爲StartDateEndDate都包含時間分量。刪除它使用Date屬性:

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

// your query goes here... 
0

在這種情況下您的日期是在查詢相同的使用(而不是差)「=」

0

其實,你的代碼List<OutletReportItem> Report = _outletReport.GetAllOutlets().Where(p => p.CreationDate >= StartDate && p.CreationDate <= EndDate).ToList()時初始化對象的DateTime所以日期的默認值,小時,分鐘和秒爲'00'。所以我認爲你可以使用DateTime.Compare()