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