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


I need some help. I have a fairly simple 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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
- .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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.