源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# 创建报表过程详解

  • 时间:2020-08-03 11:57 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# 创建报表过程详解
1、新建windows窗体,项目-->添加新项-->Visual C#项-->Windows Form-->windows窗体。 [img]http://files.jb51.net/file_images/article/201506/201506261502059.png[/img] 2、窗体中加入button按钮和报表控件。 [img]http://files.jb51.net/file_images/article/201506/2015062615020510.png[/img] 3、新建报表,项目-->添加新项-->reporting-->报表,生成.rdlc文件。 [img]http://files.jb51.net/file_images/article/201506/2015062615020511.png[/img] 4、在.rdlc上插入表格-->新建数据源-->数据库-->数据集-->新建连接,步骤如下: [img]http://files.jb51.net/file_images/article/201506/2015062615020512.png[/img] [img]http://files.jb51.net/file_images/article/201506/2015062615020513.png[/img] [img]http://files.jb51.net/file_images/article/201506/2015062615020614.png[/img] [img]http://files.jb51.net/file_images/article/201506/2015062615020615.png[/img] [img]http://files.jb51.net/file_images/article/201506/2015062615020616.png[/img] 5、这里输入数据库连接的服务器名,登录数据库的用户名和密码,选择数据库名称。 [img]http://files.jb51.net/file_images/article/201506/2015062615020617.png[/img] 6、选择需要用的表。 [img]http://files.jb51.net/file_images/article/201506/2015062615020618.png[/img] 7、名称可以自己写,本人没改,数据源为自己选择的数据库名称,可用数据集为表名。 [img]http://files.jb51.net/file_images/article/201506/2015062615020619.png[/img] 8、.rdlc界面在表格的第一行输入字段名,第二行点击每列右上角的小图标选择该列要显示的字段名。 [img]http://files.jb51.net/file_images/article/201506/2015062615020620.png[/img] 9、回到Form窗体点击报表右上角的小三角,选择刚刚创建的报表Report1.rdlc,数据源默认的就可以,本人在这里没有修改数据源名称还是DataSet1. [img]http://files.jb51.net/file_images/article/201506/2015062615020621.png[/img] [img]http://files.jb51.net/file_images/article/201506/2015062615020622.png[/img] 10、后台代码   public Form1() { InitializeComponent(); this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load); }    private void button1_Click(object sender, EventArgs e)//button点击事件 { reportViewer1_Load(sender, e); }    private void Form1_Load(object sender, EventArgs e) { this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load); } private void reportViewer1_Load(object sender, EventArgs e) { DataTable table = helps.GetDataTable("select ID,UserID,OID from User_Org where 1=1"); this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", table)); this.reportViewer1.RefreshReport(); } 运行程序加载: [img]http://files.jb51.net/file_images/article/201506/2015062615020723.png[/img] 点击button [img]http://files.jb51.net/file_images/article/201506/2015062615020724.png[/img] 这里写的是点击button后才加载数据。 以上所述就是本文的全部内容了,希望大家能够喜欢。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部