效果

  

xtrareport 布局

  

From 代码

  

    private DataSet Getdata()
{
DataSet ds = new DataSet();
//config配置字符串
string constr=ConfigurationManager.ConnectionStrings["constr"].ToString();
SqlConnection mycon = new SqlConnection(constr);
try
{
mycon.Open(); //表1
SqlCommand mycom = new SqlCommand("select * from dp ", mycon);
SqlDataAdapter dpt = new SqlDataAdapter(mycom);
dpt.Fill(ds, "dp"); //表2
SqlCommand mycom2 = new SqlCommand("select * from duser ", mycon);
dpt = new SqlDataAdapter(mycom2);
dpt.Fill(ds, "duser");
mycon.Close(); //创建主外键
DataColumn parent = ds.Tables["dp"].Columns["dpid"];
DataColumn child = ds.Tables["duser"].Columns["dpid"]; //添加关系并指定为RelationColumn
DataRelation rel = new DataRelation("RelationColumn", parent, child);
ds.Relations.Add(rel); }
catch (Exception ex)
{ MessageBox.Show(ex.Message);
} return ds; } private void simpleButton1_Click(object sender, EventArgs e)
{
DataSet ds=Getdata();
XtraReport1 report = new XtraReport1(ds);
report.Landscape = true;
documentViewer1.DocumentSource = report;
report.CreateDocument();
}
}

Xtrareport 代码

  

      public XtraReport1(DataSet ds)
{
InitializeComponent();
//绑定主表
this.DataSource = ds;
this.DataMember = "dp";
this.xrTableCell1.DataBindings.Add("Text", ds, "dp.dpname");
//指定从表成员
DetailReport.DataMember = "RelationColumn";
//绑定从表
DetailReport.DataSource = ds;
this.xrTableCell2.DataBindings.Add("Text", ds, "RelationColumn.userid");
this.xrTableCell3.DataBindings.Add("Text", ds, "RelationColumn.username"); }

注意事项

  dataset数据集中绑定了两个表,一定要看清楚有没有填充进去,没有填充的话,从表不会显示数据的

Devexpress Xtrareport 创建主从报表的更多相关文章

  1. [原创]Devexpress XtraReports 系列 3 创建主从报表

    昨天写了系列的第二篇Devexpress XtraReports 系列 2 创建表格报表 . 今天我们来继续系列 3 创建主从报表 首先我们来看看最后实现的效果.Demo最后附上. 开始吧. 第一步, ...

  2. [原创]Devexpress XtraReports 系列 5 创建交叉报表

    昨天我们已经介绍了如何创建多栏报表,详见:[原创]Devexpress XtraReports 系列 4 创建多栏报表 今天我们继续我们的XtraReports系列.Demo和数据库文件最后会附上. ...

  3. [原创]Devexpress XtraReports 系列 6 创建并排报表

    昨天我们已经介绍了如何创建交叉报表,详见:[原创]Devexpress XtraReports 系列 5 创建交叉报表 今天我们继续我们的XtraReports系列.Demo和数据库文件最后会附上. ...

  4. DevExpress XtraReports 入门四 创建 Web 报表

    原文:DevExpress XtraReports 入门四 创建 Web 报表 本文只是为了帮助初次接触或是需要DevExpress XtraReports报表的人群使用的,为了帮助更多的人不会像我这 ...

  5. Devexpress Xtrareport 并排报表

    什么是并排报表呢? 按照我个人理解:并排报表是把两张或者两张以上的报表,放在一个报表页面. 注:为了方便,本示例使用同一个数据源,但是您可以使用相同的方法,而在一个报表文档中显示两个完全不同的 (使用 ...

  6. Devexpress Xtrareports 创建多栏报表

    根据官方回答:多列或多行(取决于当前的多栏设置)呈现数据的报表 这种报表是有用的,例如,当每个明细区都只显示少量数据.并且需要在一列的右侧打印下一个明细区时,这样就能充分利用整个页面的宽度,此外,当创 ...

  7. [原创]Devexpress XtraReports 系列 2 创建表格报表

    昨天发表了Devexpress XtraReports系列开篇,今天我们继续. 今天的主题是创建表格报表. 首先我们来看看最后实现的效果.Demo最后附上. 接下来开始讲解如何一步一步做出这个报表: ...

  8. [原创]Devexpress XtraReports 系列 8 创建Drill-Through报表

    哎,今天公司工作忙了一天,一直没有时间写写东西.所以只能昨天晚上加班写咯.苦逼啊...... 昨天发表了Devexpress XtraReports系列第七篇[原创]Devexpress XtraRe ...

  9. [原创]Devexpress XtraReports 系列 10 创建标签报表

    今天这篇是Dx Reports 基础初级系列的最后一篇了.以后如果有什么高级的应用,应该另开一个中级使用系列. 昨天发表了Devexpress XtraReports系列第九篇[原创]Devexpre ...

随机推荐

  1. FPM工具 实战定制nginx包

    FPM主要特点: 把一种包打包成另一种包的格式 支持的源类型包 DIR 将目录打包成所需要的类型,可以用于源码编译的安装包. RPM    对rpm进行转换 gem    对rubygem包进行转换. ...

  2. UWP&WP8.1 基础控件——Border

    border 是边框控件 border是UWP和WP8.1最常用的控件之一. border字面意义是用来添加边框的. 基础用法 <border BorderThickness="1&q ...

  3. 【图灵学院10】高并发之java线程池源码分析

    1. 提纲 1)线程池的模块结构 2)示例&原理解析 2. 问题 1)线程池包含哪些东西 2)线程池的运作原理 3)调度线程池的运作原理 4)线程池怎么实现FixRate,FixDelay,他 ...

  4. AJAX使用四步曲

    前言 AJAX这个东西还是很模糊的,下面会对AJAX这个技术进行详细讲解一些,另外,在网上商城中应用到了,使用它有四个步骤,下面详细介绍一些. 内容 定义: AJAX=异步JavaScript和XML ...

  5. LAMP实战之构建博客网站

    1.首先检查LAMP环境 [root@cairui htdocs]# ps -ef | grep httpd php Mar03 ? :: /opt/apache2.2.34/bin/httpd -k ...

  6. 基本css拼图形

    关闭按钮: <em class="close"></em> .close { width: 16px; height: 16px; text-align: ...

  7. Linux安装步骤

    1.查看Linux系统是32位还是64位 #查看系统位数 getconf LONG_BIT #或者 uname -m #或者 arch #或者 file /sbin/init 2.IP配置 网络选择桥 ...

  8. Nexus 相关

    https://help.sonatype.com/repomanager3/download https://www.jianshu.com/p/5fc8fb14d25c

  9. SQL 模糊查询 可以正则匹配 (转)

    1. % 表示任意0个或多个字符.如下语句:Select * FROM user Where name LIKE '%三%'; 将会把name为“张三”,“三脚猫”,“唐三藏”等等有“三”的全找出来. ...

  10. 直播点赞,上升的动画-- CAKeyFrameAnimation

    // //  ViewController.m //  DMHeartFlyAnimation // //  Created by Rick on 16/3/9. //  Copyright © 20 ...