WINN2012
asked on
Vb 2010 .Net Report
Does anyone have an example of a report using Report Viewer that includes 1 or more sub-reports?
I have been all over the web and can't seem to find one that explains in detail how to implement with VB 2010. .Net.
Tons of examples using Crystal Reports with 2010 .Net
Any help would be appreciated.
Thanks
MW
I have been all over the web and can't seem to find one that explains in detail how to implement with VB 2010. .Net.
Tons of examples using Crystal Reports with 2010 .Net
Any help would be appreciated.
Thanks
MW
ASKER
That worked perfect. My problem now is I dragged textboxes onto my report. Report looks great until I want more than 1 record. I read online that you have to use the table to display more than 1 record? Â What if I have a report that has fields all over it and the grid wont work?
Thanks
MW
Thanks
MW
As you read, if you want to show a list of records then you have to use details view.
ASKER
I basically have a form I am recreating and need to print 1 out for each record.
MW
MW
ASKER
I basically have a form I am recreating and need to print 1 out for each record.
MW
MW
ASKER
I can live with printing 1 record at a time.
I have a main report with 3 sub reports, each using its own subreportprocessing handler but for some reason all 3 subreports display the data from the first sub report.
My main report only has 1 dataset listed. Each of the handlers have dataset1 in the reportdatasource code
Thanks
MW
I have a main report with 3 sub reports, each using its own subreportprocessing handler but for some reason all 3 subreports display the data from the first sub report.
My main report only has 1 dataset listed. Each of the handlers have dataset1 in the reportdatasource code
Thanks
MW
So you need to specify separate datasets for each handler.
ASKER
i am using the following:
With a handler for each sub report:
Private Sub IssueTrackerWeeklyRpt_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim Connection As New SqlClient.SqlConnectionStr ingBuilder
    Dim myConnection As SqlConnection
    Connection.DataSource = "WWWWWWW"
    Connection.InitialCatalog = "FES Issue Tracking"
    Connection.UserID = "user"
    Connection.Password = "password"
    Connection.ConnectTimeout = 5
    Try
      myConnection = New SqlConnection(Connection.C onnectionS tring)
      'you need to provide password for sql server
      myConnection.Open()
      With Me.ReportViewer1.LocalRepo rt
        ' Report path
        .ReportPath = Application.StartupPath & "\Reports\IssueTrackerWeek ly.rdlc"
        .DataSources.Clear()
      End With
      Dim SQL As String = ""
      ' -------------------------- ---------- ---------- ------
      ' Datasource for the main report Not Assigned and Not Closed
      ' -------------------------- ---------- ---------- ------
      SQL = "SELECT Issues.ID, Issues.Title, Issues.OpenedDate, Status.Status, Contacts.FullName AS AssignedTo," & _
         " Contacts_1.FullName AS OpenedBy, Priority.Priority, Issues.AssignedTo AS AssignedToID" & _
         " FROM Issues" & _
         " INNER JOIN Status ON Issues.Status = Status.ID" & _
         " INNER JOIN Contacts AS Contacts_1 ON Issues.OpenedBy = Contacts_1.ID" & _
         " INNER JOIN Priority ON Issues.Priority = Priority.PriorityID" & _
         " INNER JOIN Contacts ON Issues.AssignedTo = Contacts.ID" & _
         " WHERE Contacts.FullName = 'Not Assigned' AND Status.Status <> 'Closed'" & _
         " ORDER BY Issues.ID DESC"
      Using da As New SqlDataAdapter(SQL, myConnection)
        Using ds As New DataSet
          da.Fill(ds, "issues")
          ' You must use the same name as defined in the report
          ' Data Source Definition
          Dim rptDataSource As New ReportDataSource("DataSet1 ", ds.Tables("issues"))
          Me.ReportViewer1.LocalRepo rt.DataSou rces.Add(r ptDataSour ce)
          AddHandler ReportViewer1.LocalReport. SubreportP rocessing, AddressOf IssueTrackerWeekly2
          AddHandler ReportViewer1.LocalReport. SubreportP rocessing, AddressOf IssueTrackerWeekly3
          AddHandler ReportViewer1.LocalReport. SubreportP rocessing, AddressOf IssueTrackerWeekly4
        End Using
      End Using
      ' Refresh the report
      ReportViewer1.RefreshRepor t()
    Catch ex As Exception
      MessageBox.Show(ex.Message , My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    Me.ReportViewer1.RefreshRe port()
  End Sub
  Sub IssueTrackerWeekly2(ByVal sender As Object, ByVal e As SubreportProcessingEventAr gs)
    ' #### OPENED THIS WEEK ####
    Try
      Call findFirstLastDayOfWeek()
      Dim SQL As String = ""
      SQL = "SELECT Issues.ID, Issues.Title, Issues.OpenedDate, Status.Status, Contacts.FullName AS OpenedBy," & _
         " Priority.Priority, Contacts_1.FullName AS AssignedTo" & _
         " FROM Issues" & _
         " INNER JOIN Status ON Issues.Status = Status.ID" & _
         " INNER JOIN Contacts ON Issues.OpenedBy = Contacts.ID" & _
         " INNER JOIN Priority ON Issues.Priority = Priority.PriorityID" & _
         " INNER JOIN Contacts AS Contacts_1 ON Issues.AssignedTo = Contacts_1.ID" & _
         " WHERE OpenedDate >= '" & weekStartDate & "' AND OpenedDate <= '" & weekEndDate & "'" & _
         " ORDER BY Issues.ID DESC"
      Using da As New SqlDataAdapter(SQL, myConnection)
        Using ds As New DataSet
          da.Fill(ds, "DataSet2")
          Dim rptDataSource As New ReportDataSource("DataSet2 ", ds.Tables("Issues"))
          e.DataSources.Add(rptDataS ource)
        End Using
      End Using
    Catch ex As Exception
      MessageBox.Show(ex.Message , My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
  End Sub
With a handler for each sub report:
Private Sub IssueTrackerWeeklyRpt_Load
    Dim Connection As New SqlClient.SqlConnectionStr
    Dim myConnection As SqlConnection
    Connection.DataSource = "WWWWWWW"
    Connection.InitialCatalog = "FES Issue Tracking"
    Connection.UserID = "user"
    Connection.Password = "password"
    Connection.ConnectTimeout = 5
    Try
      myConnection = New SqlConnection(Connection.C
      'you need to provide password for sql server
      myConnection.Open()
      With Me.ReportViewer1.LocalRepo
        ' Report path
        .ReportPath = Application.StartupPath & "\Reports\IssueTrackerWeek
        .DataSources.Clear()
      End With
      Dim SQL As String = ""
      ' --------------------------
      ' Datasource for the main report Not Assigned and Not Closed
      ' --------------------------
      SQL = "SELECT Issues.ID, Issues.Title, Issues.OpenedDate, Status.Status, Contacts.FullName AS AssignedTo," & _
         " Contacts_1.FullName AS OpenedBy, Priority.Priority, Issues.AssignedTo AS AssignedToID" & _
         " FROM Issues" & _
         " INNER JOIN Status ON Issues.Status = Status.ID" & _
         " INNER JOIN Contacts AS Contacts_1 ON Issues.OpenedBy = Contacts_1.ID" & _
         " INNER JOIN Priority ON Issues.Priority = Priority.PriorityID" & _
         " INNER JOIN Contacts ON Issues.AssignedTo = Contacts.ID" & _
         " WHERE Contacts.FullName = 'Not Assigned' AND Status.Status <> 'Closed'" & _
         " ORDER BY Issues.ID DESC"
      Using da As New SqlDataAdapter(SQL, myConnection)
        Using ds As New DataSet
          da.Fill(ds, "issues")
          ' You must use the same name as defined in the report
          ' Data Source Definition
          Dim rptDataSource As New ReportDataSource("DataSet1
          Me.ReportViewer1.LocalRepo
          AddHandler ReportViewer1.LocalReport.
          AddHandler ReportViewer1.LocalReport.
          AddHandler ReportViewer1.LocalReport.
        End Using
      End Using
      ' Refresh the report
      ReportViewer1.RefreshRepor
    Catch ex As Exception
      MessageBox.Show(ex.Message
    End Try
    Me.ReportViewer1.RefreshRe
  End Sub
  Sub IssueTrackerWeekly2(ByVal sender As Object, ByVal e As SubreportProcessingEventAr
    ' #### OPENED THIS WEEK ####
    Try
      Call findFirstLastDayOfWeek()
      Dim SQL As String = ""
      SQL = "SELECT Issues.ID, Issues.Title, Issues.OpenedDate, Status.Status, Contacts.FullName AS OpenedBy," & _
         " Priority.Priority, Contacts_1.FullName AS AssignedTo" & _
         " FROM Issues" & _
         " INNER JOIN Status ON Issues.Status = Status.ID" & _
         " INNER JOIN Contacts ON Issues.OpenedBy = Contacts.ID" & _
         " INNER JOIN Priority ON Issues.Priority = Priority.PriorityID" & _
         " INNER JOIN Contacts AS Contacts_1 ON Issues.AssignedTo = Contacts_1.ID" & _
         " WHERE OpenedDate >= '" & weekStartDate & "' AND OpenedDate <= '" & weekEndDate & "'" & _
         " ORDER BY Issues.ID DESC"
      Using da As New SqlDataAdapter(SQL, myConnection)
        Using ds As New DataSet
          da.Fill(ds, "DataSet2")
          Dim rptDataSource As New ReportDataSource("DataSet2
          e.DataSources.Add(rptDataS
        End Using
      End Using
    Catch ex As Exception
      MessageBox.Show(ex.Message
    End Try
  End Sub
I only see IssueTrackerWeekly2 in your code. Do you have different Where condition in code of IssueTrackerWeekly3 and IssueTrackerWeekly4?
ASKER
Yes I have different handlers for 3 and 4. Just didnt cut and paste them.
MW
MW
I just noticed that you are assigning different event handlers to same event.
Check example here
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.subreportprocessing(v=vs.80).aspx
Check example here
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.subreportprocessing(v=vs.80).aspx
ASKER
Hmmm
I'm not quite following that code and how to implement it in my code.
MW
I'm not quite following that code and how to implement it in my code.
MW
There is only one event handler for all subreports. You need to use e.Parameters collection in that event to determine what datasource you need to supply to the subreport which is currently being processed. I have not done it myself so not sure about specifics.
ASKER
In the example you provided its the line:
Dataset.ReadXml ("C:\MyReports\OrderData.x ml")
That has my confused.
To date I haven't done anything with xml.
I have been usinf sql statements , da and ds to populate my datasets.
MW
Dataset.ReadXml ("C:\MyReports\OrderData.x
That has my confused.
To date I haven't done anything with xml.
I have been usinf sql statements , da and ds to populate my datasets.
MW
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Woot,
That makes sense, worked like a champ.
TYVM
MW
That makes sense, worked like a champ.
TYVM
MW
http://www.codeproject.com/Articles/36881/Microsoft-Reporting-Services-Sub-Reports-Charts-Pa
http://www.codeproject.com/Tips/81988/How-to-Create-Subreport-using-Microsoft-Reporting