Help with Report Viewer
My Items table contains items with each item has a specific date. I want to generate a report that displays items between two different dates. For example, I'd put two timedatepicker controls so the user selects From: 24/9/2009 To: 19/3/2010 and then press a button to generate a report of items between these dates.
I'm using Report Viewer control btw not crystal repor开发者_运维知识库t.
Edit:
Alright I figured it out using linq query and bind it to datasource like this:
var query = from c in MyDatabase01DataSet.Items
where c.ProductDate >= Convert.ToDateTime(x) && c.ProductDate <= Convert.ToDateTime(y)
select c;
ItemsBindingSource.DataSource = query.ToList();
reportViewer1.LocalReport.ReportEmbeddedResource = "[reportTest.Report3.rdlc";
reportViewer1.LocalReport.ReportPath = "Report3.rdlc";
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.RefreshReport();
Use date(From/to) in the where clause of your query. Or if you have it in a
DataTable
, use.Select
to filter specific records. Something like following:string strFilter = "dateFromCol > " + DateFrom.Value + " and dateToCol < " + DateTo.Value; yourTable.Select(strFilter);
Bind the .DataSource property with your DataTable.
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("yourDataSourceName", yourTable));
Refresh your ReportViewer
This article has simple example that might help you get started.
var query = from c in MyDatabase01DataSet.Items
where c.ProductDate >= Convert.ToDateTime(x) && c.ProductDate <= Convert.ToDateTime(y)
select c;
ItemsBindingSource.DataSource = query.ToList();
reportViewer1.LocalReport.ReportEmbeddedResource = "[reportTest.Report3.rdlc";
reportViewer1.LocalReport.ReportPath = "Report3.rdlc";
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.RefreshReport();
精彩评论