[RESOLVED] Filtering data for Report Programmatically
Hi I am loading my report and using this line of codes
Code:
Dim reportData As New ReportDataSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\\Report1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Dim ds As New WindowsApplication1.DataSet1
Dim da As New WindowsApplication1.DataSet1TableAdapters.tbl_sentTableAdapter
da.Fill(ds.tbl_sent)
reportData = New ReportDataSource("DataSet1", ds.Tables(0))
Me.ReportViewer1.LocalReport.DataSources.Add(reportData)
Me.ReportViewer1.RefreshReport()
End Sub
I'm thinking how can I change the command if I want to filter the output on my report.
on my table I have 'date' column. I want to insert a filter by date range sql command on my current code.
Re: Filtering data for Report Programmatically
Since your using a typed dataset as your datasource, all you have to do is add new query to the sentTableAdapter in the datasource. The query select statement would have two parameters, like startdate and enddate. Then fill the datatable using that "Fill" method. Something like this, this format is for an MS Access database
Quote:
Dim da As New WindowsApplication1.DataSet1TableAdapters.tbl_sentDateRangeTableAdapter
da.FillByInvoiceDateRange(ds.tbl_sent, dateStart, dateEnd)
Re: Filtering data for Report Programmatically
Quote:
Originally Posted by
wes4dbt
Since your using a typed dataset as your datasource, all you have to do is add new query to the sentTableAdapter in the datasource. The query select statement would have two parameters, like startdate and enddate. Then fill the datatable using that "Fill" method. Something like this, this format is for an MS Access database
Yup, that's what I'm doing now.
As I read from articles about TableAdapter.
I'll keep update this thread on my progress
Re: Filtering data for Report Programmatically
Here is my working and complete codes.
Code:
Imports Microsoft.Reporting.WinForms
Public Class rptViewerRequest
Dim reportData As New ReportDataSource
Private Sub rptViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DateTimePicker1.CustomFormat = "yyyy-MM-dd HH:MM:ss"
DateTimePicker2.CustomFormat = "yyyy-MM-dd HH:MM:ss"
End Sub
Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGen.Click
Dim tag As Integer
If cboRep.SelectedIndex = 0 Then
Me.ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\\Report1.rdlc"
Me.ReportViewer1.ProcessingMode = ProcessingMode.Local
tag = 1
Else
Me.ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\\Report2.rdlc"
Me.ReportViewer1.ProcessingMode = ProcessingMode.Local
tag = 2
End If
Me.ReportViewer1.LocalReport.DataSources.Clear()
Dim ds As New WindowsApplication1.DataSet1
Dim da As New WindowsApplication1.DataSet1TableAdapters.tbl_sentTableAdapter
da.FillReq(ds.tbl_sent, tag, DateTimePicker1.Value(), DateTimePicker2.Value())
reportData = New ReportDataSource("DataSet1", ds.Tables(0))
Me.ReportViewer1.LocalReport.DataSources.Add(reportData)
Me.ReportViewer1.RefreshReport()
End Sub
End Class
and here is the Query I've put into my TableAdapter in DataSet1
Code:
SELECT id, reciever, content, flag, dateSent, tag
FROM tbl_sent
WHERE (tag = @tag) AND (dateSent BETWEEN @dateSentStart AND @dateSentEnd)