一、下载安装Microsoft.RdlcDesigner.vsix设计器。
二、安装包:Microsoft.ReportingServices.ReportViewerControl.Winforms 和 Microsoft.SqlServer.Types
可以在vs中NuGet进行安装
核心的dll文件
我测试的项目目标框架是 .NET Framework 4
三、Microsoft.ReportViewer编译后,生成了多国语言包处理
现象:
处理方法:
右键项目属性-生成事件-后期生成事件命令行
输入文本:
rd /s /q "de" "en" "es" "fr" "hu" "it" "ja" "ko" "pr-br" "ro" "pt-br" "ru" "sv" "zh-hans" "zh-hant" "pt"
四、添加ReportViewer控件
点击浏览 找到安装的 Microsoft.ReportViewer.WinForms.dll 点击完成,就可以看到对应控件了。
拖拽出控件,绑定报表文件
五、添加报表文件
右键项目---添加项----报表(rdlc后缀)
这儿的数据源和结果集 可以自动映射;也可以查询出来进行动态绑定
public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { //方法一 //this.employeeTableAdapter.Fill(this.VerifyDataADataSet.employee); //this.reportViewer1.RefreshReport(); //方法二 DataTable dt = new DataTable();//可以查询数据库填充datatable ReportDataSource DataSet2 = new ReportDataSource("DataSet2", dt); this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.ReportPath = @".ReportReport1.rdlc";//设置报表路径 this.reportViewer1.LocalReport.DataSources.Add(DataSet2); this.reportViewer1.RefreshReport();//刷新报表 this.reportViewer1.RefreshReport(); } }