RDLC系列之一 简介和入门

一、简介

  RDLC报表,通过Report Viewer Control来实现,制作微软RDLC报表由以下三部分构成:1.制作自己的DateSet集合(就是报表的数据集);2.制作自己的报表文件.rdlc文件,用于画做报表样式,里面有微软自带的导出和打印功能。制作显示报表的前台页面aspx文件,基本上就是插入一个ReportViewer然后关联上面的.rdlc文件,注意别忘了更新数据源和插入ScriptManager.

   这种报表的易用性和可定制性,主要功能:
       1、简单易用的控件,特别是Table控件,非常方便字段在报表上的排列;
       2、灵活的可定制性,用XML来描述一个报表相关的一切;
       3、高度可编程性,在你的项目中,甚至不需要有一个报表文件,通过代码就可以实现报表生成、预览和打印等一系列操作;
       4、支持DrillThrough数据钻取功能;
       5、导出的Excel文件格式非常完美,任何其它报表在这方面都不能与之比拟,而且并不需要安装Excel;

 

  需要注意的是在vs2017 vs2019中已经没有集成,需要手动安装

  1推荐nuget安装:Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms

  2下载地址:https://marketplace.visualstudio.com/items?itemName=ProBITools.MicrosoftRdlcReportDesignerforVisualStudio-18001

  添加可参考:VS2019添加ReportViewer

 

二、入门

一、效果图

二、过程图解

1.创建一个winform项目,添加报表控件

2.创建一个数据集

创建表

3.创建报表RDLC

4。添加数据集到报表

5.在rldc中添加表,指定列

6.参数

 

项目文件:

7.代码 

using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RdlcDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //自定义数据源
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            DataRow dr = null;
            dr = dt.NewRow();
            dr[0] = 1;
            dr[1] = "li";  
            dt.Rows.Add(dr);
            //自定义参数
            List<ReportParameter> list = new List<ReportParameter>();
            ReportParameter rp = new ReportParameter("pid", "11");
            list.Add(rp);

            this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\Report1.rdlc";
            this.reportViewer1.LocalReport.DataSources.Clear(); 
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt));//指定数据源
            this.reportViewer1.LocalReport.SetParameters(list); //参数设置 
            this.reportViewer1.RefreshReport();
        }
    }
}

 

图解:DataSet1为该名称,非数据源名称

 

 

 注意:rdlc文件属性

 

 

参照文章:

http://www.cnblogs.com/waxdoll/archive/2006/07/24/458409.html#!comments

http://waxdoll.cnblogs.com/archive/2006/02/25/337713.html

http://www.cnblogs.com/zhwl/p/3283924.html

 

posted @ 2015-05-14 18:31  心存善念  阅读(1767)  评论(0编辑  收藏  举报