zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    leetcode刷题37
    leetcode刷题36
    leetcode刷题38
    leetcode刷题35
    leetcode刷题34
    leetcode刷题33
    记一次Unity使用XNode插件时自动连线问题
    Unity中UGUI图片跟随文本自适应
    Unity中多个物体交换位置
    使用VSCode编译C
  • 原文地址:https://www.cnblogs.com/newwind521/p/889935.html
Copyright © 2011-2022 走看看