zoukankan      html  css  js  c++  java
  • RDLC报表,纯文字内容,动态数据源 解决方案

    最近在做一个教育相关的项目,遇到很多的报表,在一位学长的推荐下使用了RDLC。

    这个系统基本上都是简单的查询数据,没有别的复杂的功能,下简单记录下个人使用心得,以便以后使用。

    如果能帮到需要了解RDLC的人更是非常开心。

    系统是 三层架构 + 存储过程 开发

    数据库连接字符串在Web.Config存储,经常会改变。

    网上很多的RDLC教程都是说数据源都是说添加数据源,然后拖过来一个表什么的,但是这对于实际项目显然不缺实际,因此需要改变思路。

    我的方法是:手动添加一个 数据集 Dataset

     

    然后,右击add->column 添加存储过程或者其他数据源所查询到的所有的数据列。

    然后添加RDLC报表文件,菜单栏选择 报表->数据源

    选中新建的DATASET,然后添加到报表。

    一般显示数据都是用表格,故拖出一个表格,在第二行,详细信息里右击选择表达式。

    弹出如下对话框。

    可选内容很多。因为我们制定的是数据集,选择字段就可以看到。然后双击就得到表达式。

    当然也可以选择其他,比如参数。可以在报表界面 选择 报表- 报表参数,添加参数。

    这里报表就配置好了。

    剩下的就是显示了。需要一个asp.net空间 ReportViewer.

    在适当的时候为它赋数据源。

    代码如下:

    private CommonLogic mCommonLogic = null;
    private SqlParameter[] mSqlParameters = null;

    private Microsoft.Reporting.WebForms.ReportParameter[] mReportParams = null;

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    if (Request.QueryString["ReportPath"] != null)
    {
    ViewState[
    "ReportPath"] = Request.QueryString["ReportPath"];
    mCommonLogic
    = new CommonLogic("Report" + ViewState["ReportPath"]);
    }

    mSqlParameters
    = (SqlParameter[])Session["Parameters"];
    for (int i = 0; i < mSqlParameters.Length; i++)
    {
    if (mSqlParameters[i].Value != null && mSqlParameters[i].Value.ToString() == "---请选择---")
    {
    mSqlParameters[i].Value
    = DBNull.Value;
    }
    }

    DataTable aTable
    = mCommonLogic.ExecFun((SqlParameter[])Session["Parameters"]);

    ReportViewer1.Reset();
    ReportViewer1.LocalReport.ReportPath
    = MapPath("~/tab/report/" + ViewState["ReportPath"].ToString() + ".rdlc");
    ReportViewer1.LocalReport.DataSources.Add(
    new Microsoft.Reporting.WebForms.ReportDataSource(ViewState["ReportPath"] + "_" + ViewState["ReportPath"], aTable));
    if (Session["ReportParams"] != null)
    {
    mReportParams
    = (Microsoft.Reporting.WebForms.ReportParameter[])Session["ReportParams"];
    ReportViewer1.LocalReport.SetParameters(mReportParams);
    }
    ReportViewer1.LocalReport.Refresh();

    Session.Remove(
    "Parameters");
    Session.Remove(
    "ReportParams");
    }
    }

  • 相关阅读:
    荔枝微课基础架构的演进与实践
    如何制作出让女朋友满意的大片
    SSL 证书变革之时已至,这些变化你都清楚吗?
    浅谈 FTP、FTPS 与 SFTP
    HTTP/3 来了,你了解它么?
    看视频常见的 720p、1080p、4k,这些分辨率到底包含了什么
    element-ui表单验证遇到v-if时不生效
    声纹识别算法阅读之CN-Celeb
    apply-cmvn&apply-cmvn-online&apply-cmvn-slide
    语音识别算法阅读之TDNN-F
  • 原文地址:https://www.cnblogs.com/jeekun/p/1936530.html
Copyright © 2011-2022 走看看