C#簡單水晶報表列印步驟

來源:互聯網
上載者:User

1.建立項目Print

 

2.主介面添加一個按鈕,和水晶報表預覽處理常式

3.右擊資源管理員,添加一個資料集

 

3.按步驟添加自己的資料庫到資料集中

 

4.添加完畢,再右擊項目,建立添加水晶報表

 

5.接著選擇報表裡面需要的表,欄位,按步驟操作,完成後如下

6.接著雙擊剛才添加的按鈕,裡面主要代碼如下

步驟是串連資料庫,建立與資料庫連接的適配器SqlDataAdapter,把剛才添加的資料集MyReortData,建立一個,然後Fill添加到SqlDataAdapter;接著建立水晶報表,設定資料來源,接著再給水晶報表預覽處理常式設定資料來源

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace TestLogin{    public partial class Form_print : Form    {        public Form_print()        {            InitializeComponent();        }        SqlDataAdapter da;        private void button1_Click(object sender, EventArgs e)        {            DataOpt daa = new DataOpt();            daa.SQLConn();            MyReortData mydata = new MyReortData();            da = new SqlDataAdapter("SELECT  * FROM score INNER JOIN student ON score.studentno = student.studentno", daa.conn);            da.Fill(mydata, "DataTable1");            CrystalReport1 cr = new CrystalReport1();            cr.SetDataSource(mydata);            crystalReportViewer1.ReportSource = cr;        }    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.