我有一个水晶报告,其中有一个子报告嵌入其页脚。报告单独工作正常,但当我一起运行时,我不会在子报告中获取数据。我已经验证了我的2个数据集中存在数据,并且我获得了主要报告的数据,但没有得到子数据。我错过了什么? (VS 2008 4.0 .NET Framework)
// check whether the dataset is manual; if so add the subreport queries
if (AARpt.HasSubreports)
{
string srName;
string sProc;
using (AAData dc = new AAData(AAApp, true))
{
for (int i = 0; i < cRpt.ReportDefinition.ReportObjects.Count; i++)
{
ReportObject CurrentObject = cRpt.ReportDefinition.ReportObjects[i];
if (CurrentObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
SubreportObject sr = (SubreportObject)CurrentObject;
rd = sr.OpenSubreport(sr.SubreportName );
srName = sr.SubreportName;
if (AARpt.SubReps.TryGetValue(srName, out sProc))
{
dsSubRept = dc.LoadSet(sProc);
if (dsSubRept != null)
{
DataTable dt1 = ds.Tables["MyTable"];
rd.SetDataSource(dt1);
rd.VerifyDatabase();
}
else
{
MessageBox.Show("We're sorry, but an error was encountered attempting to create this report","Utility", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
}
}
}
}
}
public DataSet LoadSet(SqlCommand _cmd)
{
// returns table "MyTable"
SqlDataAdapter DA;
DataSet DS = new DataSet();
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Connection = _Conn;
DA = new SqlDataAdapter(_cmd);
DA.Fill(DS, "MyTable");
return DS;
}
答案 0 :(得分:0)
我使用错误的数据集作为子报告....否则它是完美的。更新了以下代码。
// check whether the dataset is manual; if so add the subreport queries
if (AARpt.HasSubreports)
{
string srName;
string sProc;
using (AAData dc = new AAData(AAApp, true))
{
for (int i = 0; i < cRpt.ReportDefinition.ReportObjects.Count; i++)
{
ReportObject CurrentObject = cRpt.ReportDefinition.ReportObjects[i];
if (CurrentObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
SubreportObject sr = (SubreportObject)CurrentObject;
rd = sr.OpenSubreport(sr.SubreportName );
srName = sr.SubreportName;
if (AARpt.SubReps.TryGetValue(srName, out sProc))
{
dsSubRept = dc.LoadSet(sProc);
if (dsSubRept != null)
{
// Following line added (not sure if needed, but was suggested in several spots)
rd.DataSourceConnections.Clear();
// The datasource in the following line changed - this was my real issue
DataTable dt1 = dsSubRept.Tables["MyTable"];
rd.SetDataSource(dt1);
rd.VerifyDatabase();
}
else
{
MessageBox.Show("We're sorry, but an error was encountered attempting to create this report","Utility", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
}
}
}
}
}
// The following is part of a class for loading data, but it is straightforward otherwise
// I just included so you know that it returns a DataSet with a table named "MyTable"
public DataSet LoadSet(SqlCommand _cmd)
{
// returns table "MyTable"
SqlDataAdapter DA;
DataSet DS = new DataSet();
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Connection = _Conn;
DA = new SqlDataAdapter(_cmd);
DA.Fill(DS, "MyTable");
return DS;
}