利用VS2015自带的报表制作报表

我用的是VSEnterprise2015

注意:如果要用VS自带的报表,就需要在安装Microsoft SQL Server Data Tools

下面讲讲具体步骤:

1.添加winform界面

2.添加生成报表界面这里要注意,工具箱的数据里面要有ReportViewer控件,如果没有则要工具箱-》数据-》选择项-》.NET Framework组件-》勾选ReportViewer(命名空间对应的是Microsoft.Reporting.WinForms【winform程序,如果是asp.net则勾选命名空间是Microsoft.Reporting.WebForms】)

生成报表界面对应代码

            try
            {
                this.reportViewer1.LocalReport.ReportPath = "Report_JSHZB.rdlc";//Report_JSHZB.rdlc对应添加的报表文件
                DataTable dt = new DataTable();
                dt.Columns.Add("BMMC");
                dt.Columns.Add("JYBS", typeof(int));//对应报表文件中的数据集字段
                dt.Columns.Add("JYJE", typeof(decimal));
                dt.Columns.Add("HCBS", typeof(int));
                dt.Columns.Add("HCJE", typeof(decimal));
                dt.Columns.Add("JSJE", typeof(decimal));
                dt.Rows.Add("第一食堂", 13305, 27246.68, 0, 0.0, 27246.68);
                dt.Rows.Add("第二食堂", 12277, 27965.63, 1, 15.0, 27950.63);
                dt.Rows.Add("超市", 26, 1062.90, 0, 0.0, 1065.90);
                dt.Rows.Add("医务室", 78, 857.00, 0, 0.0, 857.00);
                dt.Rows.Add("电子阅览室", 157, 871.00, 0, 0.0, 871.00);
                dt.Rows.Add("图书馆", 120, 1176.50, 0, 0.0, 1176.50);
                dt.Rows.Add("学生公寓沐浴", 693, 5371.19, 0, 0.0, 5371.19);
                ReportDataSource rds1 = new ReportDataSource("DataSet_JSHZB", dt);//DataSet_JSHZB对应报表文件中的数据集
                this.reportViewer1.LocalReport.DataSources.Add(rds1);
                ReportParameter Rar_CNDate = new ReportParameter();
                Rar_CNDate.Name = "Rar_CNDate";//报表参数,对应报表文件中的参数
                Rar_CNDate.Values.Add(CNDate.ToString("yyyy-MM-dd"));
                ReportParameter Rar_Time = new ReportParameter();
                Rar_Time.Name = "Rar_Time";
                Rar_Time.Values.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                ReportParameter Rar_UserName = new ReportParameter();
                Rar_UserName.Name = "Rar_UserName";
                Rar_UserName.Values.Add("系统管理员");
                this.reportViewer1.LocalReport.SetParameters(Rar_CNDate);
                this.reportViewer1.LocalReport.SetParameters(Rar_Time);
                this.reportViewer1.LocalReport.SetParameters(Rar_UserName);
                this.reportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.reportViewer1.RefreshReport();

 

3.添加报表文件

4.最终生成的报表

 

转载于:https://www.cnblogs.com/luoxiaozhao/p/5602718.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值