在Crystal Report Windows应用程序中添加子报告c# [英] Add Sub Report in Crystal Report windows application c#

查看:82
本文介绍了在Crystal Report Windows应用程序中添加子报告c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Good After Noon

这是Hem Raj Thakur,我想在水晶报告中添加子报告所有报告中的Header部分(windows应用程序) C#.net)。

我正在添加子报告并输入如下代码:---

-------------- ----------------------------------------------

  private   void  Area_Report_Load( object  sender,EventArgs e)
{
try
{
string str = 选择a.areaname为Area_Name,b.cname为国家/地区,c.sname为州,d.dname为区域,来自tbl_area,内部联接tbl_country b位于a.cid = b.cid内部联接tbl_district d位于a.did = d.did和b.cid = d.cid内部联接t.sl_state c在a.sid = c.sid和a.cid = c.cid和d.sid = cs ID;
SqlDataAdapter da = new SqlDataAdapter(str,con);
DataSet_Area ds = new DataSet_Area();
da.Fill(ds);

string str1 = 从tbl_Department中选择depid,depname,loc;
SqlDataAdapter da1 = new SqlDataAdapter(str1,con);
DataSet_Dept ds1 = new DataSet_Dept();
da.Fill(ds1);

CrystalReport_Area report = new CrystalReport_Area();
report.SetDataSource(ds.Tables [ 1 ]);
crystalReportViewer1.ReportSource = report;
// crystalReportViewer1.Refresh();
// -----------------------添加子报告---- -----------------
ReportDocument subreport = new ReportDocument();
// 错误子报告未加载请求帮助?
subreport.Load ( CrystalReport_Dept.rpt); // - 子报告未加载
// subreport.Load(Server.MapPath(CrystalReport6.rpt));
subreport.Database.Tables [ 0 ]。SetDataSource(ds1.Tables [ 1 ]);
report.Subreports [ CrystalReport_Dept.rpt]。SetDataSource(ds1.Tables [< span class =code-digit> 1
]);
}
catch (例外)
{}
}



----------------------------------------------- --------

请帮帮我。 紧急 ..........



提前感谢。

问候

Hem Raj Thakur

解决方案

为什么不在主报表的设计时添加子报表?


< blockquote>刚发现问题。你做错了订单。将以下行移至最后(应该是结束行块。

 crystalReportViewer1.ReportSource = report; 



添加后应将 Reportsource 分配给 crystalReportViewer 子报告的东西。



编辑

--------------

Quote:

是先生我检查但错误显示为加载报告失败。此行错误跳转到catch块后该行是: ----- subreport.Load(CrystalReport_Dept.rpt);

检查此提示/技巧

Crystal Reports:修复加载报告失败错误。 [ ^ ]


hi to all,
Good After Noon
this is Hem Raj Thakur and I want to add sub report in a crystal report Header part in all report(windows application C#.net).
I am adding a sub report and type a code like:---
------------------------------------------------------------

private void Area_Report_Load(object sender, EventArgs e)
{
   try
   {
      string str = "select a.areaname as Area_Name, b.cname as Country,c.sname as State,d.dname as District from tbl_area a inner join tbl_country b on a.cid = b.cid inner join tbl_district d on a.did = d.did and b.cid = d.cid inner join tbl_state c on a.sid =c.sid and a.cid = c.cid and d.sid =c.sid";
      SqlDataAdapter da = new SqlDataAdapter(str, con);
      DataSet_Area ds = new DataSet_Area();
      da.Fill(ds);

      string str1 = "select depid,depname,loc from tbl_Department";
      SqlDataAdapter da1 = new SqlDataAdapter(str1, con);
      DataSet_Dept ds1 = new DataSet_Dept();
      da.Fill(ds1);

      CrystalReport_Area report = new CrystalReport_Area();
      report.SetDataSource(ds.Tables[1]);
      crystalReportViewer1.ReportSource = report;
      //crystalReportViewer1.Refresh();
      //-----------------------Add Sub Report---------------------
      ReportDocument subreport = new ReportDocument();
      //Error Sub Report is not loading please help?
      subreport.Load("CrystalReport_Dept.rpt"); //--Sub Report is not Load
      //subreport.Load(Server.MapPath("CrystalReport6.rpt"));
      subreport.Database.Tables[0].SetDataSource(ds1.Tables[1]);
      report.Subreports["CrystalReport_Dept.rpt"].SetDataSource(ds1.Tables[1]);
   }
   catch (Exception)
   { }
}


-------------------------------------------------------
Please help Me. It is Urgent..........

thanks in advance.
regards
Hem Raj Thakur

解决方案

Why not add the subreport on the design time of the main report?


Just spotted the issue. You're doing wrong order. Move the below line to last(should be ending line of try block.

crystalReportViewer1.ReportSource = report;


You should assign the Reportsource to crystalReportViewer after adding the subreport things.

EDIT
--------------

Quote:

yes sir i check but error is display like "Load report failed." after this line error jumps on catch block the line is:----- subreport.Load("CrystalReport_Dept.rpt");

Check this Tip/Trick
Crystal Reports: Fix for "Load report failed" error.[^]


这篇关于在Crystal Report Windows应用程序中添加子报告c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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