我用的是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("第一食堂", , 27246.68, , 0.0, 27246.68);
dt.Rows.Add("第二食堂", , 27965.63, , 15.0, 27950.63);
dt.Rows.Add("超市", , 1062.90, , 0.0, 1065.90);
dt.Rows.Add("医务室", , 857.00, , 0.0, 857.00);
dt.Rows.Add("电子阅览室", , 871.00, , 0.0, 871.00);
dt.Rows.Add("图书馆", , 1176.50, , 0.0, 1176.50);
dt.Rows.Add("学生公寓沐浴", , 5371.19, , 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.最终生成的报表

最新文章

  1. easyUI datagrid 根据查询条件 选中对应数据的行
  2. c++中函数中变量内存分配以及返回指针、引用类型的思考
  3. jQuery EasyUI教程之datagrid应用(三)
  4. vs2010 调试快捷键
  5. cocos2d-x NotificationCenter
  6. Nginx模块开发入门(转)
  7. Mirantis MCP 1.0:OpenStack 和 Kubernetes 整合的第一步
  8. 史上最简单的js+css3实现时钟效果
  9. struts2 --xml配置
  10. VGA、DVI、HDMI三种视频信号接口
  11. iOS原生实现二维码拉近放大
  12. 【OpenStack】相关概念
  13. eclipse 启动tomcat 出现错误Could not publish server configuration: null. java.lang.NullPointerException
  14. JavaScript 获取鼠标点击位置坐标
  15. 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组
  16. android 点击通知栏返回应用 ,非启动一个新Activity
  17. windows 2008R2 iis7 +php web环境安装
  18. Linux输入子系统:多点触控协议 -- multi-touch-protocol.txt768
  19. iOS开发之JSONKit
  20. Replication--复制笔记1

热门文章

  1. 关于synchronized和Lock
  2. 使用 SpringBoot 配置发送邮件功能
  3. php 使用fseek指针读取大文件日志
  4. 使用jQuery对象
  5. 大转盘抽奖css3+js(简单书写)
  6. poj 3254 Corn Field
  7. 理解MITRE ATT&CK矩阵
  8. hdu多校第九场 1006 (hdu6685) Rikka with Coin 暴力
  9. fasttext源码剖析
  10. linux安装&卸载IB网卡(mellanox)驱动