• VS2005中的水晶报表也可以用推模式动态绑定数据源


    看到很多人说vs2005中的水晶报表不再支持用推模式动态绑定数据源的操作,经试验按如下方法也可以完成:
    步骤如下:
    1.设计报表模板Report1.rpt,与数据源查询的结果集一致,如果数据源复杂,可先做一视图,用视图来设计报表和生成DataSet或DataTable.
    2.在aspx页面上托入报表查看器CrystalReportViewer1和报表源控件CrystalReportSource1.
    3.编码从表或视图中查询数据生成DataSet或DataTable.
    4.用DataSet创建报表文件(ReportDoument),并绑定到报表查看器.
    代码如下:

            //存储过程名
            string strSql = "SubPlanAndLast";
      //连接字符串
            string strCon = ConfigurationManager.ConnectionStrings["SqlCon"].ToString();
            SqlConnection con = new SqlConnection(strCon);
            SqlDataAdapter da = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand(strSql, con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@year", year);
            da.SelectCommand = cmd;
            DataTable dt = new DataTable();
            da.Fill(dt);

            CrystalReportSource1.ReportDocument.Load(Server.MapPath("Report1.rpt"));
            //注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
            CrystalReportSource1.ReportDocument.SetDataSource(dt);
            CrystalReportSource1.DataBind();
            CrystalReportViewer1.ReportSource = CrystalReportSource1;
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.BestFitPage = true;
            CrystalReportViewer1.Width = Unit.Pixel(400);

  • 相关阅读:
    python笔记1
    git笔记
    手撸一个简陋直播系统
    spring-boot学习笔记1
    设计模式1--简单工厂模式
    网联:第一章:浏览器生成消息
    php线上预览日志--4.websocket客户端
    php线上预览日志--3.websocket服务部署
    php线上预览日志--2.谷歌插件开发
    php线上预览日志--1.概述
  • 原文地址:https://www.cnblogs.com/newwind521/p/889935.html
Copyright © 2020-2023  润新知