fastreport代码转

2016-07-08

//打印主从表数据
string file = Application.StartupPath @"\MasterDetail.frx";
rptMasterDetail.Load(file);//加载报表模板文件

DataSet ds = DAL.GetMasterDetailData();//取报表数据

rptMasterDetail.RegisterData(ds.Tables[0], "tb_SO"); //注册数据源,主表
rptMasterDetail.RegisterData(ds.Tables[1], "tb_SOs"); //注册数据源,从表

//
//直接注册DataSet也行,但必须对DataSet.Tables指定表名!
//FastReport是跟据表名取DataTable对象的。
//
//rptMasterDetail.RegisterData(ds);
//

//给DataBand(主表数据)绑定数据源
DataBand masterBand = rptMasterDetail.FindObject("Data1") as DataBand;
masterBand.DataSource = rptMasterDetail.GetDataSource("tb_SO"); //主表

//给DataBand(明细数据)绑定数据源
DataBand detailBand = rptMasterDetail.FindObject("Data2") as DataBand;
detailBand.DataSource = rptMasterDetail.GetDataSource("tb_SOs"); //明细表

//重要!!给明细表设置主外键关系!
detailBand.Relation = new Relation();
detailBand.Relation.ParentColumns = new string[] { "SONO" };
detailBand.Relation.ParentDataSource = rptMasterDetail.GetDataSource("tb_SO"); //主表
detailBand.Relation.ChildColumns = new string[] { "SONO" };
detailBand.Relation.ChildDataSource = rptMasterDetail.GetDataSource("tb_SOs"); //明细表

//准备工作,显示报表预览窗体
rptMasterDetail.Prepare();
rptMasterDetail.ShowPrepared(true, this);

转载于:https://www.cnblogs.com/lhyqzx/p/5652735.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值