Let's go

C#微软下的Rdlc报表使用

一、下载安装Microsoft.RdlcDesigner.vsix设计器。

下载链接:https://probitools.gallerycdn.vsassets.io/extensions/probitools/microsoftrdlcreportdesignerforvisualstudio-18001/15.3.1/1555453080956/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 = @".\Report\Report1.rdlc";//设置报表路径
            this.reportViewer1.LocalReport.DataSources.Add(DataSet2);
            this.reportViewer1.RefreshReport();//刷新报表
            this.reportViewer1.RefreshReport();
        }
    }

 

posted @ 2021-04-23 09:47  chenze  阅读(2381)  评论(0编辑  收藏  举报
有事您Q我