C#建立無資料來源水晶報表極簡教程

來源:互聯網
上載者:User

有人說我寫東西比較囉嗦,呵呵,這次簡單點。

 

先建個水晶報表工程

 

建立完後,先把報表介面關了,建立個dataset

 

 

  在裡面建立個表,mytable

 

 

 根據需要定義幾個欄位

 

然後設計報表,選資料來源

 

 

報表如下

 

 

在表單裡寫上代碼

 

 

 1  private void Form1_Load(object sender, EventArgs e)
 2         {
 3             //填充dataset,這裡就可以承接任何介面,資料庫,數組啥得都行
 4             DataSet1 ds1 =new DataSet1();
 5             ds1.mytable.AddmytableRow("a1","a2","a3","a4","a5",1,1,1,1,1);
 6             ds1.mytable.AddmytableRow("b1","b2","b3","b4","b5",1,1,1,1,1);
 7             ds1.mytable.AddmytableRow("c1","c2","c3","c4","c5",1,1,1,1,1);
 8             ds1.mytable.AddmytableRow("d1","d2","d3","d4","d5",1,1,1,1,1);
 9             ds1.mytable.AddmytableRow("e1","e2","e3","e4","e5",1,1,1,1,1);
10 
11             CrystalReport1 cr1 =new CrystalReport1();
12             cr1.SetDataSource (ds1);
13             crystalReportViewer1.ReportSource = cr1;
14         }

 

 

這就完成了~~

 

PS1

可以配合 http://www.cnblogs.com/babyt/archive/2008/01/03/1024941.html 實現更靈活的效果

PS220080917: 補充一下一個基礎的資料庫讀取,替換文中的自填充ds段:

SqlConnection conn = new SqlConnection("server=xxx.;Uid=sa;Pwd=;database=test"); 
conn.Open(); 
SqlDataAdapter da = new SqlDataAdapter("select a1,b1,c1,d1,e1 from test", conn);
DataSet ds = new DataSet();
da.Fill(ds1, "mytable");  //特別注意此處的表名,需與設計時的表名一致
conn.Close();

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.