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

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

利⽤VS2015⾃带的报表制作报表
我⽤的是VSEnterprise2015
注意:如果要⽤VS⾃带的报表,就需要在安装Microsoft SQL Server Data Tools
下⾯讲讲具体步骤:
1.添加winform界⾯
2.添加⽣成报表界⾯这⾥要注意,⼯具箱的数据⾥⾯要有ReportViewer控件,如果没有则要⼯具箱-》数据-》选择项-》.NET Framework组件-》勾选ReportViewer(命名空间对应的是Microsoft.Reporting.WinForms【winform程序,如果是则勾选命名空间是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_ = "Rar_CNDate";//报表参数,对应报表⽂件中的参数
Rar_CNDate.Values.Add(CNDate.ToString("yyyy-MM-dd"));
ReportParameter Rar_Time = new ReportParameter();
Rar_ = "Rar_Time";
Rar_Time.Values.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
ReportParameter Rar_UserName = new ReportParameter();
Rar_ = "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.最终⽣成的报表。

相关文档
最新文档