• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2389
  • Last Modified:

Crystal Reports .NET & Subreport - Hekp with pushing dataset into subreport?


I need some help. I have a fairly simple CR.net report that works great. I'm using the PUSH method, so I made an .xsd file with the data schema to create my report, I query the DB and fill a dataset in code, then pass it to the report as shown in the code snippet.

This works great and I have the ability to "massage" the data in the DS before I push it out to the CR report.

Problem is that I want to add a subreport using the same data access method. I've created the subreport xsd file, built the report itself and added all my fields. I added the second, new report to my other report as a subreport and linked the proper main report ID field to the subreport ID field.

But I can't seem to figure out how to call the Report.SetDataSource() method on the subreport. I can't find a Report.SubReport property as I've seen shown on some of these postings for this type of issue.

Also, whenever I run the code it keeps asking me for database logon information - which shouldn't even be involved since I'm pulling the data from the DB myself in code. The reports don't know anything about my database connections and shouldn't need to.

If anyone knows how to pass a DS to a linked subreport or knows of a good write up on how to do this, please let me know.

Thanks a lot,

Dim ADP As New SqlClient.SqlDataAdapter(qry.ToString, con)
Dim DSx As New DataSet
ADP.Fill(DSx, "ReportData")
Dim Rpt As New rptStandardCageV2
CRViewer.ReportSource = Rpt

Open in new window

  • 2
1 Solution
georgeb3Author Commented:
Awww...come on...someone out there must know how to do this! Think, think hard!

georgeb3Author Commented:
Nevermind I figured it myself.
But I will post the steps that I used, and which worked for me, for all other's out there running into a similar situation.

- CR version: CR.net
- .NET version 1.1 (2003)
- Windows app (but also work in web app)

1. set up xsd dataset files for the main report and any subreports. Make sure the reports use the xsds as their datasources rather than DB connections. Make sure you have the subreport(s) fields linked to the main report fields.
2. In code, dim main report object as the actual report.rpt file (see code snippet)
3. dim sub report(s) as ReportDocument - NOT as the actual rpt file!!! (see snippet)
4. Now associate the subreport with the main report - this is what I was missing before! (see snippet). NOTE: You have to use the actual name for the subreport RPT file!
5. Set the DataSource for the main report and any subreports.
6. Set the report source for the CR viewer object.

Hopefully, this helps everyone out there in the same predicament. Now you can push datasets into your subreports.

    Dim Rpt As New rptStandardCageV2   'rptStandardCageV2.rpt is the actual  
                                       'rpt file name!
    Dim RptSub As New ReportDocument   'use generic ReportDocument
    RptSub = Rpt.OpenSubreport("rptLabelsV2.rpt")
     CRViewer.ReportSource = Rpt

Open in new window


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now