zoukankan      html  css  js  c++  java
  • VS2005中水晶報表在C#.NET WEB應用程式中與ADO.NET的結合(收藏)

    大致操作:
    a  建立ADO.NET資料集---DataSet1.xsd
    b 建立CrystalReports--CrystalReport.rpt
    c  設計WEB頁面 拉入報表顯示控件---CrystalReportViewer
    d  相關後台編碼
        添加相關引用
           連接數據庫
        用相關查詢的結果填充DataSet1的實例對象
        建立ReportDocument--rptDoc
           rptDoc載入報表 rptDoc.Load("...")
        設定rptDoc的資料來源 rptDoc.SetDataSource(ds)
        通過頁面的報表檢視器顯示報表  crViewer.ReportSource = rptDoc

    實例步驟:
    1 新建web專案

    2  在專案中新增ADO.NET資料集-DataSet1.xsd

      專案右鍵-加入新項目-資料集

    3  建立資料連接
      
      伺服器總管-資料連接-右鍵-加入資料連接

    4 將資料表(如tablename)放入剛才所建的資料集

      具體就是從資料庫中將該表拉入資料集設計界面即可

    5 儲存並建置專案

    -----------

    6 新增Crystal Reports報表-CrystalReport.rpt

      專案-右鍵-加入新項目-Crystal Reports

    7  使用標准報表專家 建立報表

    8 使用ADO.NET資料集 做為資料來源

    9 選擇加入相關表的相關樣位到報表中顯示

    10 使用標准樣式

    11 儲存並建置專案

    ----------

    12 設計表單 拉入工具樣中的 CrystalReportViewer

    13  編寫該WEB頁面的後台代碼

    14 加入如下參考:
      using System.Data.SqlClient
        usint CrystalDecisions.CrystalReports.Engine

    15  在適當位置編寫如下相關代碼
      
      建立資料庫連線
      SqlConnection sqlconn = new SqlConnection("server=localhost;database=db;uid=uid;pwd=pwd;");
        sqlconn.Open();
       
      建立SQL指令
       SqlDataAdapter sda = new SqlDataAdapter("select * from table", sqlconn);

        取回資料放入資料集
      DataSet1 ds = new DataSet1();//注意 此處用的是 剛才所建立的資料集 而不是慣用的DataSet
        sda.Fill(ds, "tablename");//注意 此處的tablename 要與剛才在建立資料集時 用到的tablename相同

        建立報表物體-rptDoc
        ReportDocument rptDoc = new ReportDocument();

        載入報表-CrystalReport.rpt
        rptDoc.Load(this.Server.MapPath("./").ToString() + "/CrystalReport.rpt");

      將報表物體的資料來源設定為ds
        rptDoc.SetDataSource(ds);

        以報表檢視器顯示報表
        this.CrystalReportViewer1.ReportSource = rptdoc;
        this.CrystalReportViewer1.DataBind();

    ------------
    編譯運行 查看效果

    原文地址:http://www.cnblogs.com/xiongeee/archive/2006/11/27/574455.html

  • 相关阅读:
    Twitter如何在数千台服务器上快速部署代码?
    系统架构师学习笔记_第六章(上)_连载
    使用IIS内置压缩功能,增加网站访问速度
    系统架构师学习笔记_第八章_连载
    微软企业库4.1学习笔记(十五)缓存模块3 使用数据库作为后端存储
    快速搞懂 SQL Server 的锁定和阻塞
    微软企业库4.1学习笔记(十四)缓存模块2 使用缓存模块进行开发
    微软企业库4.1学习笔记(十六)缓存模块4 服务器场中的缓存使用
    Agile PLM Engineering Collaboration
    EC Client Customizing EC Client 客户化
  • 原文地址:https://www.cnblogs.com/CodingPerfectWorld/p/1722376.html
Copyright © 2011-2022 走看看