您的位置:首页 > 其它

VS2005中水晶報表在C#.NET WEB應用程式中與ADO.NET的結合(收藏)

2019-08-01 04:29 1026 查看
原文链接:https://www.geek-share.com/detail/2483374580.html 大致操作:
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();

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

原文地址:https://www.geek-share.com/detail/2375638760.html

转载于:https://www.cnblogs.com/CodingPerfectWorld/archive/2010/04/27/1722376.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐