多 table 数据集如何在 asp.net crystal 报告中工作
How data set with multi table working in asp.net crystal report
我用 crystal 报告测试了一个应用程序。
我创建了 1 个包含 4 table 的数据集(master、items、solution、evaluation),这是我的代码
//Master
dsMaster.Tables["master"].ImportRow(dtMaster.Rows[0]);
//Items
DataTable dtItems = getItems(_mdReqMaster.id);
if(dtItems.Rows.Count > 0){
foreach(DataRow dr in dtItems.Rows){
dsMaster.Tables["items"].ImportRow(dr);
}
}
//TeamTech
DataTable dtTechnicians = getTechnicians(_mdReqMaster.id);
if (dtTechnicians.Rows.Count > 0)
{
foreach (DataRow dr in dtTechnicians.Rows)
{
dsMaster.Tables["technicians"].ImportRow(dr);
}
}
//Solution
DataTable dtSolution = getSolution(_mdReqMaster.id);
if (dtSolution.Rows.Count > 0)
{
foreach (DataRow dr in dtSolution.Rows)
{
dsMaster.Tables["solutions"].ImportRow(dr);
}
}
//Evaluate
DataTable dtEvaluate = getEvaluate(_mdReqMaster.id);
if (dtEvaluate.Rows.Count > 0)
{
foreach (DataRow dr in dtEvaluate.Rows)
{
dsMaster.Tables["evaluation"].ImportRow(dr);
}
}
数据添加见我的图片:
report.Load(Path.Combine(
HostingEnvironment.MapPath("~/Reports/"), "report.rpt"));
//report.Database.Tables[0].SetDataSource(dsMaster.Tables[0]);
//report.Database.Tables[1].SetDataSource(dsMaster.Tables[1]);
report.SetDataSource(dsMaster);
report.Refresh();
Stream stream = report.ExportToStream(ExportFormatType.PortableDocFormat);
MemoryStream streamReader = new MemoryStream();
stream.CopyTo(streamReader);
return streamReader.ToArray();
输出:
我只从 table master 那里得到数据。当我使用数据库时。 Tables[0].SetDataSource(dsMaster.Tables[0]) 我收到登录错误,看起来我需要设置登录才能报告,我想我不需要设置它,因为我使用数据集。有人能帮助我吗?非常感谢。
您不能将 DataSource 设置为 table,只能设置为数据集。如果您打开 Crystal 报表,是否可以在 DatabaseFields 中看到所有数据表?尝试为所有数据表定义 Crystal 报告详细信息部分。所以现在您有 4 个详细信息部分,第一部分尝试将数据表 1 中的数据库字段放入数据表 2 中的第二个字段,等等。您现在的数据是可见?
我的问题是我,我在子报告中使用另一个 table 然后我需要将该数据添加到子报告
我用 crystal 报告测试了一个应用程序。 我创建了 1 个包含 4 table 的数据集(master、items、solution、evaluation),这是我的代码
//Master
dsMaster.Tables["master"].ImportRow(dtMaster.Rows[0]);
//Items
DataTable dtItems = getItems(_mdReqMaster.id);
if(dtItems.Rows.Count > 0){
foreach(DataRow dr in dtItems.Rows){
dsMaster.Tables["items"].ImportRow(dr);
}
}
//TeamTech
DataTable dtTechnicians = getTechnicians(_mdReqMaster.id);
if (dtTechnicians.Rows.Count > 0)
{
foreach (DataRow dr in dtTechnicians.Rows)
{
dsMaster.Tables["technicians"].ImportRow(dr);
}
}
//Solution
DataTable dtSolution = getSolution(_mdReqMaster.id);
if (dtSolution.Rows.Count > 0)
{
foreach (DataRow dr in dtSolution.Rows)
{
dsMaster.Tables["solutions"].ImportRow(dr);
}
}
//Evaluate
DataTable dtEvaluate = getEvaluate(_mdReqMaster.id);
if (dtEvaluate.Rows.Count > 0)
{
foreach (DataRow dr in dtEvaluate.Rows)
{
dsMaster.Tables["evaluation"].ImportRow(dr);
}
}
数据添加见我的图片:
report.Load(Path.Combine(
HostingEnvironment.MapPath("~/Reports/"), "report.rpt"));
//report.Database.Tables[0].SetDataSource(dsMaster.Tables[0]);
//report.Database.Tables[1].SetDataSource(dsMaster.Tables[1]);
report.SetDataSource(dsMaster);
report.Refresh();
Stream stream = report.ExportToStream(ExportFormatType.PortableDocFormat);
MemoryStream streamReader = new MemoryStream();
stream.CopyTo(streamReader);
return streamReader.ToArray();
输出:
我只从 table master 那里得到数据。当我使用数据库时。 Tables[0].SetDataSource(dsMaster.Tables[0]) 我收到登录错误,看起来我需要设置登录才能报告,我想我不需要设置它,因为我使用数据集。有人能帮助我吗?非常感谢。
您不能将 DataSource 设置为 table,只能设置为数据集。如果您打开 Crystal 报表,是否可以在 DatabaseFields 中看到所有数据表?尝试为所有数据表定义 Crystal 报告详细信息部分。所以现在您有 4 个详细信息部分,第一部分尝试将数据表 1 中的数据库字段放入数据表 2 中的第二个字段,等等。您现在的数据是可见?
我的问题是我,我在子报告中使用另一个 table 然后我需要将该数据添加到子报告