C# 創(chuàng)建報表過程詳解
1、新建windows窗體,項目-->添加新項-->Visual C#項-->Windows Form-->windows窗體。
2、窗體中加入button按鈕和報表控件。
3、新建報表,項目-->添加新項-->reporting-->報表,生成.rdlc文件。
4、在.rdlc上插入表格-->新建數(shù)據(jù)源-->數(shù)據(jù)庫-->數(shù)據(jù)集-->新建連接,步驟如下:
5、這里輸入數(shù)據(jù)庫連接的服務器名,登錄數(shù)據(jù)庫的用戶名和密碼,選擇數(shù)據(jù)庫名稱。
6、選擇需要用的表。
7、名稱可以自己寫,本人沒改,數(shù)據(jù)源為自己選擇的數(shù)據(jù)庫名稱,可用數(shù)據(jù)集為表名。
8、.rdlc界面在表格的第一行輸入字段名,第二行點擊每列右上角的小圖標選擇該列要顯示的字段名。
9、回到Form窗體點擊報表右上角的小三角,選擇剛剛創(chuàng)建的報表Report1.rdlc,數(shù)據(jù)源默認的就可以,本人在這里沒有修改數(shù)據(jù)源名稱還是DataSet1.
10、后臺代碼
public Form1()
{
InitializeComponent();
this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load);
}
private void button1_Click(object sender, EventArgs e)//button點擊事件
{
reportViewer1_Load(sender, e);
}
private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load);
}
private void reportViewer1_Load(object sender, EventArgs e)
{
DataTable table = helps.GetDataTable("select ID,UserID,OID from User_Org where 1=1");
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", table));
this.reportViewer1.RefreshReport();
}
運行程序加載:
點擊button
這里寫的是點擊button后才加載數(shù)據(jù)。
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關文章
automation服務器不能創(chuàng)建對象 解決方法
本文主要介紹如何解決“automation服務器不能創(chuàng)建對象”錯誤,從而解決Visual Studio.Net不能正常使用的問題,需要的朋友可以參考下。2016-06-06詳解Unity中Mask和RectMask2D組件的對比與測試
本篇文章給大家介紹Unity中Mask和RectMask2D組件的對比與測試,包括組件用法及RectMask2D的基本用法,通過Mask的原理分析實例代碼相結合給大家講解的非常詳細,需要的朋友參考下吧2021-06-06