cancel
Showing results for 
Search instead for 
Did you mean: 

Subreport Using Different Dataset

Former Member
0 Kudos

I am getting "The table could not be found". The table it refers to is my main report table. The report has a main table and sub report based on a view. I am trying to set the data source for the the sub report to a different dataset than the main report. I have named both the tables in the dataset and are setting the report source for them.

I also have the code that logs into all the sub report and report tables. My report worked fine before I added the sub report. Can you have a report and sub report with different data sources?

I am using Crystal Reports XI Release II and VS 2005. I am designing the reports in Crystal with Oracle Views and setting the data from VB.net based on Datasets built from querying the views..

If WaterCheck.blSOU Then

Report.Subreports("propSOU").SetDataSource(WaterCheck.propSOU)

End If

Dim tablename As String = ds.Tables(0).ToString

Report.SetDataSource(ds.Tables(tablename))

End if

Edited by: Kevin Cloud on Oct 23, 2008 2:39 PM

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

You have to set the dataset to the main report and the subreport. Two options there:

explicitly

crReportDocument.Database.Tables(0).SetDataSource(dataSet.Tables("NAME_OF_TABLE"))

implicitly

crReportDocument.SetDataSource(dataSet) or crReportDocument.SetDataSource(dataSe.Tables(0))

Now, depending on the report, the dataset, etc., you may have to do the same for the subreport. Here is a snippet of code to use:

crSubreportDocument = crReportDocument.OpenSubreport("Ron")

.

.

.

your .SetDataSource code here

.

.

.

Alternatively, you can loop through the report, looking for subreport objects, then use the .SetDataSource. E.g.;

Dim crSections As Sections

Dim crSection As Section

Dim crSubreportObject As SubreportObject

'set the crSections object to the current report's sections

crSections = crReportDocument.ReportDefinition.Sections

'loop through all the sections to find all the report objects

For Each crSection In crSections

crReportObjects = crSection.ReportObjects

'loop through all the report objects to find all the subreports

For Each crReportObject In crReportObjects

If crReportObject.Kind = ReportObjectKind.SubreportObject Then

'you will need to typecast the reportobject to a subreport

'object once you find it

crSubreportObject = CType(crReportObject, SubreportObject)

'open the subreport object

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)

'set the database and tables objects to work with the subreport

<your .SetDataSource code here>

Next

End If

Next

Ludek

Former Member
0 Kudos

I have tried so many ways that I have become frustrated. This is what I learned, If I don't set my subreport objects then my main object works fine. if I don't set my main report object then subreport works fine by itself. If I set them both then the report can't find the table for my main report. I have tried the "opensubreport" method for setting the data. I have tried combining the datasets into one. Nothing works.

I have decided after one day of messing with this that it isn't worth the trouble. So I am creating a temporary table on our database and using that as a source for the subreport and letting the report query that based on a foreign key. This is what the other subreports do on this report. The problem was this data is something that I calculated in code and does not come from a table on Oracle, so I will insert it into a temp table for the report and delete it when the report is destroyed.

Thanks for the response.

Answers (0)