Print Page | Close Window

Subreport not showing data

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2766
Printed Date: 18 May 2024 at 10:17am


Topic: Subreport not showing data
Posted By: Wooger
Subject: Subreport not showing data
Date Posted: 31 Mar 2008 at 10:40am
Hi,

I'm using VS2005 C++ to view a Crystal report in the CrystalReportViewer that is embedded in a Form.  I'm having some problem setting the data source in my subreports, whenever I try to do this the subreport never has any data in it even though I know there is data in the DataSet that I just set as the data source.  The main report shows up fine with the correct data. 

 My reports and subreports are being created by hooking up to an XSD file and then I fill the dataset in the code, with each subreport having a different dataset.  Here are some of the ways I have to set the subreport datasource but have had no luck -

 DS = gcnew DataSet("BULDataSet"); //This is the main report dataset

RptCommand = gcnew SqlCommand("SELECT * FROM Subject WHERE Subject.LastName = 'Schroeder'", Conn);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter->Fill(DS);

RptDoc->SetDataSource(DS);  //RptDoc is the main report document

 

subDS = gcnew DataSet("BULDataSet"); //subreport dataset

RptCommand = gcnew SqlCommand("SELECT * FROM Company WHERE Company.Id = 1", Conn);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter->Fill(subDS);

 

RptDoc->Subreports["subreport1"]->SetDataSource(subDS);

or

RptDoc->OpenSubreport("subreport1")->SetDataSource(subDS);

or

 System::Collections::IEnumerator^ EnumSubRpt = RptDoc->Subreports->GetEnumerator();

 while(EnumSubRpt->MoveNext()){

 

SubRptDoc = (ReportDocument^)EnumSubRpt->Current;

SubRptDoc->SetDataSource(subDS);

}

However, I have noticed that if I set my main report dataset as the data source for my subreport or my subreport dataset is taken from the same table that the main report queried, than I can get information to show up on the subreport.

So let's say my main report query was -

SELECT * FROM Subject WHERE Subject.LastName = 'Johnson'

and my subreport query was

SELECT * FROM Subject WHERE Subject.Id = 12345

then data will show up on my subreport, but this is of no use to me since in practice the main dataset and subreport dataset take information from different tables.  What is causing this problem I am having?




Replies:
Posted By: Wooger
Date Posted: 31 Mar 2008 at 12:16pm
I also should note that I am creating the reports using Crystal Reports XI and not the version that is bundled with Visual Studio 2005.


Posted By: pgeorge
Date Posted: 17 Apr 2009 at 4:26am
i realise this was an old post, but did you solve this problem. I have the same issue that the data in subreports are not getting displayed.

I have a report created from xsd and the data in the array inside the object also does not display. Any ideas?


Posted By: mrrcomp
Date Posted: 03 May 2011 at 5:00pm
Hi
 
This is a very old post but I have the same type of situation and was wondering if either of you have found the reason or solution.
 
Regards
 
Meir
ConfusedConfusedConfusedConfusedConfusedConfused



Print Page | Close Window