效果

  

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. 小 M 的算式(dfs)

    [问题描述]小 M 在做数学作业的时候遇到了一个有趣的问题:有一个长度为 n 的数字串 S,小 M 需要在数字之间填入若干个“+”和恰好一个“=”,使其成为一个合法的等式.如对于 S=“2349”,可 ...

  2. 通过pip3安装virtualenvwrapper

    pip3 install virtualenvwrapper 配置virtualenvwrapper创建虚拟环境的目录和指定python3版本 环境编辑当前用户配置变量 mkdir ~/.virtua ...

  3. sqlite3使用备忘

    执行sqlite3进入sqlite3环境: $ sqlite3 SQLite version -- :: Enter ".help" for usage hints. Connec ...

  4. AI-Info-Micron-Insight:工业 5.0,伟大的思想将殊途同归

    ylbtech-AI-Info-Micron-Insight:工业 5.0,伟大的思想将殊途同归 1.返回顶部 1. 工业 5.0,伟大的思想将殊途同归 两个头脑比一个好吗?似乎如此,尤其是当其中一个 ...

  5. poj1811(pollard_rho模板)

    题目链接: http://poj.org/problem?id=1811 题意: 判断一个数 n (2 <= n < 2^54)是否为质数, 是的话输出 "Prime" ...

  6. bootstrap添加模态窗后,再弹出消息提示框后,原先的滚动条消失

    设置需要滚动的模态框 overflow :scroll

  7. CF796A Buying A House 模拟

    Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains ...

  8. 新建maven 父子模块项目

    第一步: 第二步: 先创建个简单的空架结构作为父项目 第三步: 创建子项目 第四步: 切换显示不同的maven子项目显示方式 关于maven中的parent聚合一直都有没好好总结,固有这篇. ---- ...

  9. Python迭代器生成器,模块和包

      1.迭代器和生成器 2.模块和包 1.迭代器 迭代器对象要求支持迭代器协议的对象,在Python中,支持迭代器协议就是实现对象的__iter__()和__next__()方法.    其中__it ...

  10. Django 09 博客小案例

    Django 09 博客小案例 urls.py from django.urls import path from . import views urlpatterns = [ path('index ...