[英]How data set with multi table working in asp.net crystal report
I test an application with crystal report. 我使用Crystal Report测试应用程序。 I create 1 dataset with 4 tables (master, items, solution, evaluation) and this is my code
我用4个表(主,项目,解决方案,评估)创建1个数据集,这是我的代码
//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);
}
}
Data added see my picture: 添加的数据见我的照片:
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();
Output: 输出:
I get only data from table master. 我仅从表母版获取数据。 And when I use Database.
当我使用数据库时。 Tables[0].SetDataSource(dsMaster.Tables[0]) I get login error, looks like I need to set login to report and I think I don't need to set that because I use dataset.
Tables [0] .SetDataSource(dsMaster.Tables [0])我收到登录错误,看起来我需要将登录设置为报表,并且我认为不需要设置该值,因为我使用数据集。 Can someone help me, please?
有人能帮助我吗? Thank you so much.
非常感谢。
You cant SetDataSource to a table, only to dataset.. If you open your CrystalReport, can you see all your DataTables in DatabaseFields? 您不能将SetDataSource设置为表,而只能设置为数据集。。如果打开CrystalReport,可以在DatabaseFields中看到所有的DataTables吗? Try to define Crystal Report details sections for all of your DataTables.. so now you have 4 details sections, and to first section try to put db fields from DataTable1, to second from DataTable2, etc.. Are your data now visible?
尝试为所有DataTables定义Crystal Report详细信息部分。.因此,现在您有4个详细信息部分,在第一部分中,尝试将DataTable1中的db字段放到DataTable2中的第二个字段中,依此类推。您的数据现在可见了吗?
我的问题是我,我在子报表中使用了另一个表,那么我需要将该数据添加到子报表中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.