-
Apr 17th, 2013, 01:04 PM
#1
Thread Starter
Addicted Member
[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.
-
Apr 18th, 2013, 07:14 AM
#2
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.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 18th, 2013, 09:41 AM
#3
Thread Starter
Addicted Member
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.
Thanks again,
Stacy
-
Apr 18th, 2013, 09:53 AM
#4
Thread Starter
Addicted Member
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.
-
Apr 19th, 2013, 03:54 AM
#5
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.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 23rd, 2013, 03:00 PM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|