I have taken on an existing vb.net project done in Visual Studio 2008 with crystal reports version Crystal Report XI.
The reports on their own work very well. Problem is I need to add information to my report which is a 'many-to-one' situation where for each Project Id that I am displaying I need to display several attached documents and the report I am working on is for several Project Id's.
I figured this would be a perfect situation for a SubReport. I created a separate report which calls a stored procedure to get all of the Attached Documents for a specific Project Id. I thought if I were to add this new SubReport to the Original Report and link the Project Id's, easy-peazy, I would be done.
This is not the case. I have vb code that loads the Original Report with a stored procedure and when this code runs with the setup I described above it fails when it is creating the final report with the following error:
Logon failed. Details: crdb_adoplus : Object reference not set to an instance of an object. Error in File C:\~\ProjectDescriptionReport {6BA19F79-2A12-4826-B1F6-456EF799963B}.rpt: Unable to connect: incorrect log on parameters.
I have no specific connections in my vb code for the reports. If I do not add the subreport to the main report, it loads correctly, so I know the error is caused by the subreport.
This is the code that creates the original report (sorry for dumping the code here, i just thought it would be easier to see all the code) :
Public Function LoadReport(ByVal inProjectNum As Integer, ByVal strProjectName As String) As DataTable ', ByVal inFiscalYear As Integer, ByVal inCompany As String) As DataTable
Dim cnn As SqlConnection = Nothing
Dim cmd As Data.SqlClient.SqlCommand
Dim obj As New clsDataClass
Dim dataAdapter As SqlClient.SqlDataAdapter
Try
LoadReport = New DataTable("DescriptionReport")
cmd = New SqlCommand()
cnn = obj.Create_Connection()
With cmd
.CommandType = Data.CommandType.StoredProcedure
.Connection = cnn
.CommandTimeout = "60"
.CommandText = "usp_GetProjectGroupSpecsCR"
.Parameters.AddWithValue("@ProjectNumber", inProjectNum)
.Parameters.AddWithValue("@ProjectName", strProjectName)
End With
dataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = cmd
dataAdapter.Fill(LoadReport)
Dim oRpt As New ReportDocument()
oRpt.Load(Server.MapPath("ProjectDescriptionReport.rpt"))
oRpt.Refresh()
oRpt.SetDataSource(LoadReport)
'oRpt.OpenSubreport("AttachmentsReport").SetDataSource(LAR)
oRpt.SetParameterValue("inProjectNum", inProjectNum)
oRpt.SetParameterValue("strProjectName", strProjectName)
oRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "Projects_DescriptionReport") 'inCompany & "ProjectsReport_Description" & inFiscalYear) <-- Line where the error occures.
.......
What I need to know is what is the proper way to add a subreport to a vb.net application?
From the ways I have tried it is clearly not working and I am out of ideas. I am fairly new to Crystal Reports and this way of coding it.
Any help for this would be greatly appreciated, I've been stuck on this for a while and am finally reaching out to the Crystal Report Specialists.
Thank you in advance,
Bryan