Results 1 to 4 of 4

Thread: [RESOLVED] Filtering data for Report Programmatically

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Resolved [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.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,518

    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
    Dim da As New WindowsApplication1.DataSet1TableAdapters.tbl_sentDateRangeTableAdapter
    da.FillByInvoiceDateRange(ds.tbl_sent, dateStart, dateEnd)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Re: Filtering data for Report Programmatically

    Quote Originally Posted by wes4dbt View Post
    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
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    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)
    Last edited by dr_aybyd; Sep 29th, 2012 at 01:15 AM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width