[RESOLVED] VS2010 RDLC Local Report with SubReport-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] VS2010 RDLC Local Report with SubReport

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    221

    Resolved [RESOLVED] VS2010 RDLC Local Report with SubReport

    I am trying to make an rdlc report with a subreport. Both reports are using their own dataset.

    I have made my parent RDLC report, WOReportandSub.rdlc, and it works fine. I have a list and several textbox's placed on it. It is grouped on WONum.

    I then made my subreport, WOLockOutSubReport.rdlc, on which I placed one table and selected fields from my dataset. I added a parameter to the report called WONum - integer.

    Then back to the main report I placed a subReport from the toolbox and then right clicked on it and went to Subreport properties and typed in the name of my subreport exactly as it is in the project minus the .rdlc part. Visibility is set to Show. I added a Parameter called WONum and chose the value for it as my [WONum] column from my dataset. If I run just the subreport by itself I get an error that says WONum parameter is missing a value, which would be true since I didn't pass it a parameter and the Main Report didn't pass it one because I ran it by itself. So I guess I'm wondering how I get that main report to pass the variable to the subreport.

    I have a winform with all my report buttons and the code to run this report is as follows:

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ReportViewer As New ReportView
            Dim ds As New WOReport
            Dim ta As New WOReportTableAdapters.DataTable1TableAdapter
            ta.FillByAllChecked(ds.DataTable1)
    
            ReportViewer.ReportViewer1.LocalReport.ReportPath = "c:\MaintenanceTracker\MaintenanceTracker\Reports\WOReportandSub.rdlc"
            ReportViewer.ReportViewer1.LocalReport.DataSources.Clear()
    
            Dim sReportDataSource As ReportDataSource
            sReportDataSource = New ReportDataSource()
            sReportDataSource.Name = "DataSet1"
            sReportDataSource.Value = ds.DataTable1
            ReportViewer.ReportViewer1.LocalReport.DataSources.Add(sReportDataSource)
    
            AddHandler ReportViewer.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler
    
            ReportViewer.Show()
            ReportViewer.ReportViewer1.RefreshReport()
        End Sub
    The code for the subreportProcessing is as follows:
    Code:
     Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
            Try
                Dim ds As New WOLockOutSubReportDataSet
                Dim da As New WOLockOutSubReportDataSetTableAdapters.wolockTableAdapter
    
                da.Fill(ds.wolock, e.Parameters("WONum").Values(0))
    
                e.DataSources.Add(New ReportDataSource("DataSet1", ds.Tables("wolock")))
            Catch ex As Exception
                MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    The error I get when I try to run the report is "An error occurred during local report processing. Value cannot be null. Parameter name: value." I'm not sure what this means because I don't have a parameter called value it's called WONum.
    Anyway I'm sure the error is probably in this code to actually run the report, but I can't seem to figure out what is wrong. I don't pass a parameter to the Main RDLC - the fill query for the dataset is any records that have the PrintStatus column = 1. So it could be bringing up several WONum's. The query for the subreport's dataset fill is bringing up the data for the same WONum's.

    Does anyone know what I'm doing wrong. I have been working on this for days and I would really appreciate any input
    Thanks,
    Stacy
    Last edited by StacyOW; Apr 17th, 2013 at 01:13 PM.

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    3,326

    Re: VS2010 RDLC Local Report with SubReport

    I added a Parameter called WONum and chose the value for it as my [WONum] column from my dataset
    If I've understood you correctly that should be all you need to do. Just to be clear, the sub report has a parameter called WONum. In the Main report you view the properties of the sub report and go to the parameters tab. Add a parameter called WONum and set it's value to the apropriate field on you dataset. Does that describe what you did?

    Assuming you did the above then it should be passing the WONum value to your report correctly. Is it possible that or more records in your main report have a WONum that's null? If so then you would have a group where WONum is null and would be passing null (correctly) to the sub report for that group. If that's the case then you probably want to amend the sub report to allow null for the parameter.
    When one of my minions says, "Hey, he's just one guy, what can he do?" I say "This"... and shoot them.

    The problem with putting your lair in a volcano is keeping your robot army from melting.

    I know that the human being and the fish can coexist peacefully - George Bush

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    221

    Re: VS2010 RDLC Local Report with SubReport

    Thank you FunkyDexter for your reply. I've been working on this for a week now.
    Yes that is exactly what I have done - as you describe above. I have changed my records now so my Main/Parent table is only returning one record so there are no null records - but I don't think there ever were Null. WONum is the PK and auto-increment of that parent table. I have also checked that there are multiple child records that should be coming up in the subreport. I have infact tried changing the sub report to allow nulls just so it would bring up atleast my main report when I run it. But I still get that error and NO data comes up on the report not even the main report. It just shows that error. I'll send you a screen shot so you can see it.

    I have been going over and over this and finding examples on the web and I just can't seem to find where the problem is. Shouldn't I atleast get the main report when I run it even if it's not getting the value to the sub report? If I delete the subreport the main report will bring up data if I put the subreport on I get the error and no data comes up.

    Here is the image of the error on my report. Name:  ReportError.JPG
Views: 3887
Size:  30.6 KB

    Thanks again,
    Stacy

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    221

    Re: VS2010 RDLC Local Report with SubReport

    I figured it out. Somehow I had two subreports and I was making changes in one and had the other one linked in my main report. Stupid me. Didn't realize it until I moved the published version to another computer to run it and got the error that the report files were missing. Wow - sometimes when you work on something too long you loose site of the obvious.

    Anyway, thanks for you reply.
    Stacy

    P.S. It does in fact work perfectly now!

    Do you happen to know how to use several subreports on one main report? I made all the subreports and placed them on the main report and then added the code like the following:
    Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    Try
    Dim ds As New WOLockOutSubReportDataSet
    Dim da As New WOLockOutSubReportDataSetTableAdapters.wolockTableAdapter
    Dim ds1 As New WOPartsSubReportDataSet
    Dim da1 As New WOPartsSubReportDataSetTableAdapters.wopartsTableAdapter
    Dim ds2 As New WOLaborSubReportDataSet
    Dim da2 As New WOLaborSubReportDataSetTableAdapters.wolaborTableAdapter

    da.Fill(ds.wolock)
    da1.Fill(ds1.woparts)
    da2.Fill(ds2.wolabor)

    e.DataSources.Add(New ReportDataSource("DataSet1", ds.Tables("wolock")))
    e.DataSources.Add(New ReportDataSource("DataSet1", ds1.Tables("woparts")))
    e.DataSources.Add(New ReportDataSource("DataSet2", ds2.Tables("wolabor")))

    Catch ex As Exception
    MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End Sub
    But of course it doesn't work!

    Thanks,
    Stacy
    Last edited by StacyOW; Apr 30th, 2013 at 10:42 AM.

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    3,326

    Re: [RESOLVED] VS2010 RDLC Local Report with SubReport

    I always use SSRS natively rather than from VB Apps so take what I say with a pinch of salt,

    I think what you're doing there is trying to populate the datasets for all three sub reports but that event handler is going to fire individually for each of them. I think you want to interrogate e.ReportPath to see which sub report is being processed and only do the work required for that particular sub-report.


    At the moment you're adding two data sets called Dataset1 so the second will either overwrite the first or it will crash.
    When one of my minions says, "Hey, he's just one guy, what can he do?" I say "This"... and shoot them.

    The problem with putting your lair in a volcano is keeping your robot army from melting.

    I know that the human being and the fish can coexist peacefully - George Bush

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    221

    Re: [RESOLVED] VS2010 RDLC Local Report with SubReport

    Thank you FunkyDexter! I was able to get it working just the way you said.

    This is what I ended up with in case anyone is trying to do this also.
    Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    Dim zrpt = e.ReportPath

    Select Case zrpt
    Case "WOPartsSubReport"
    Dim ds1 As New WOPartsSubReportDataSet
    Dim da1 As New WOPartsSubReportDataSetTableAdapters.wopartsTableAdapter
    da1.Fill(ds1.woparts)

    e.DataSources.Add(New ReportDataSource("DataSet1", ds1.Tables("woparts")))

    Case "WOLaborSubReport"
    Dim ds2 As New WOLaborSubReportDataSet
    Dim da2 As New WOLaborSubReportDataSetTableAdapters.wolaborTableAdapter
    da2.Fill(ds2.wolabor)

    e.DataSources.Add(New ReportDataSource("DataSet1", ds2.Tables("wolabor")))

    Case "WOLockoutSubReport"
    Dim ds As New WOLockOutSubReportDataSet
    Dim da As New WOLockOutSubReportDataSetTableAdapters.wolockTableAdapter
    da.Fill(ds.wolock)

    e.DataSources.Add(New ReportDataSource("DataSet1", ds.Tables("wolock")))

    End Select
    End Sub
    Thanks again,
    Stacy

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.