Load Subreport in rdlc with parameters programmatically

DiuthToit

New Member
I'm at a loss after 2 days of trying to get this to work. I have a report that has parent information and have a subreport that should have the details of that parent info. They both work independently but when I put the subreport in, it's either blank or gives the error subreport cannot be displayed.

The current the PDF comes up with no data displayed in either the main report or the subreport. The subreport has an error. I have a parameter set on the sub.rdlc but not on the sub report properties inside the main report. I've read so much about parameters that I'm not sure what I need to do. I can't find a good walk through anywhere out there so maybe if someone can point me in the right direction that would be great.

I used this link to get where i'm at now but I'm stuck...
http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.localreport.subreport processing(VS.80).aspx


Imports System
Imports System.Data
Imports Microsoft.Reporting.WebForms
Imports System.Data.SqlClient

Partial Class report_default
Inherits System.Web.UI.Page

Dim serviceDetailsData As DataTable = Nothing
Dim ReportViewer1 As New ReportViewer()
Dim getConn As New Connection

Private Function LoadServiceData() As DataTable
Dim dataSet As New dsGeneralInfo

'Load Connection
Dim sqlConn As SqlConnection = New SqlConnection(getConn.GetCnxStringVO("connectionString"))

'Load Service Agreement--------------------------------------------------------------
Dim daServiceAgreement As New SqlDataAdapter("LL_CMI_GetServiceAgreement", sqlConn)
daServiceAgreement.SelectCommand.CommandType = CommandType.StoredProcedure
daServiceAgreement.SelectCommand.Parameters.Add(Ne w SqlParameter("@SERVICE_ID", 204160))

Try
sqlConn.Open()
daServiceAgreement.Fill(dataSet)
Catch ex As Exception
Throw New Exception("Exception binding data source to dsServiceAgreeement. " & ex.Message)
Finally
'Clean up connection
If sqlConn.State <> ConnectionState.Closed Then sqlConn.Close()
End Try

Return dataSet.Tables(0)
End Function

Private Function LoadServiceDetailsData()
Dim dataSet As New dsPhoneLineInfo

'Load Connection
Dim sqlConn As SqlConnection = New SqlConnection(getConn.GetCnxStringVO("connectionString"))

'Load Phone Line Information---------------------------------------------------------
Dim daPhoneLineInfo As New SqlDataAdapter("LL_CMI_GetPhoneLineInfo", sqlConn)
daPhoneLineInfo.SelectCommand.CommandType = CommandType.StoredProcedure
daPhoneLineInfo.SelectCommand.Parameters.Add(New SqlParameter("@SERVICE_ID", 204160))

Try
sqlConn.Open()
daPhoneLineInfo.Fill(dataSet)
Catch ex As Exception
Throw New Exception("Exception binding data source daPhoneLineInfo. " & ex.Message)
Finally
'Clean up connection
If sqlConn.State <> ConnectionState.Closed Then sqlConn.Close()
End Try

Return dataSet.Tables(0)
End Function

Public Sub DemoSubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
If (serviceDetailsData Is Nothing) Then
serviceDetailsData = http://aspmessageboard.com/archive/index.php/LoadServiceDetailsData()
End If
e.DataSources.Add(New ReportDataSource("dsPhoneLineInfo_LL_CMI_GetPhoneLineInfo", serviceDetailsData))
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf DemoSubreportProcessingEventHandler

If (Not IsPostBack) Then
'Set RDL file
ReportViewer1.LocalReport.ReportPath = Server.MapPath("activationInfo.rdlc")

'Supply a DataTable corresponding to each report data source
Dim myReportDataSource = New ReportDataSource("dsGeneralInfo_LL_CMI_GetServiceAgreement", LoadServiceData())
ReportViewer1.LocalReport.DataSources.Add(myReport DataSource)
End If

'Export to PDF
Dim pdfContent As Byte() = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

'Return PDF
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("Content-disposition", "attachment; filename=activationSummary" + "204160" + ".pdf")
Me.Response.BinaryWrite(pdfContent)
Me.Response.End()
End Sub
End Class
 
Top