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?