子报告SetDataSource问题 [英] Subreport SetDataSource problem

查看:112
本文介绍了子报告SetDataSource问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

Hi,

我正在使用VS2005 C ++查看Crystal报告在嵌入在窗体中的CrystalReportViewer中。我在子报表中设置数据源时遇到了一些问题,每当我尝试这样做时,子报表中就没有任何数据,即使我知道DataSet中有数据我只是设置为数据源。主报告显示正确的数据。

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. 

我的报告和子报告是通过连接到XSD文件创建的,然后我将数据集填入代码,每个子报表都有不同的数据集。以下是我设置子报表数据源但没有运气的一些方法 -

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" ; ); //这是主报告数据集

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

RptCommand = gcnew SqlCommand( SQLQry,Conn);

RptCommand = gcnew SqlCommand(SQLQry, Conn);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter-> Fill(DS);

RptAdapter->Fill(DS);

RptDoc-> ;的setDataSource(DS); // RptDoc是主报告文件

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

subDS = gcnew DataSet( " BULDataSet" ); //子报告数据集

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

RptCommand = gcnew SqlCommand(SubReportSQLQry,Conn) ;

RptCommand = gcnew SqlCommand(SubReportSQLQry, Conn);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter = gcnew SqlDataAdapter(RptCommand);

RptAdapter-> Fill(subDS);

RptAdapter->Fill(subDS);

RptDoc->子报告[" subreport1"] - > SetDataSource(subDS);

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

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

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

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

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

< font size = 2>

while( EnumSubRpt-> MoveNext()){


SubRptDoc =(ReportDocument ^)EnumSubRpt-> Current;

SubRptDoc = (ReportDocument^)EnumSubRpt->Current;


 


SubRptDoc - > SetDataSource(subDS);

SubRptDoc->SetDataSource(subDS);


}

}

< font size = 2>

 

但是,我注意到如果我将主报表数据集设置为子报表的数据源,或者我的子报表数据集取自主报告查询的表格与我在子报表上显示的信息相同。

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主题WHERE Subject.LastName ='Johnson'

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

和我的子报告查询

SELECT * FROM Subject WHERE Subject.Id = 12345

SELECT * FROM Subject WHERE Subject.Id = 12345

then data将显示在我的子报表上,但这对我没用,因为在实践中主数据集和子报表数据集从不同的表中获取信息。导致这个问题的原因是什么?

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?

推荐答案

更新,在SetDataSouce(subDS)调用发生后,数据肯定可用,因为我可以将变量从主报表传递到子报表,并将子报表设置为数据集中的某个变量,然后在主报表中正确打印出来。由于某种原因,它只是没有在子报表中显示数据。

An update, data is definitely available after the SetDataSouce(subDS) call happens as I can pass a variable from the main report to the subreport and have the subreport set that variable to something in the dataset and then print it out in the main report correctly.  For some reason it is just not showing the data in the subreport. 

 


这篇关于子报告SetDataSource问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆