C#如何利用ReportViewer生成報表?這篇文章運用了實例代碼展示,代碼非常詳細,可供感興趣的小伙伴們參考借鑒,希望對大家有所幫助。
創新互聯專注為客戶提供全方位的互聯網綜合服務,包含不限于網站制作、做網站、楚雄州網絡推廣、微信小程序、楚雄州網絡營銷、楚雄州企業策劃、楚雄州品牌公關、搜索引擎seo、人物專訪、企業宣傳片、企業代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創新互聯為所有大學生創業者提供楚雄州建站搭建服務,24小時服務熱線:18980820575,官方網址:m.2m8n56k.cn
涉及知識點:
ReportViewer :位于Microsoft.Reporting.WinForms命名空間, 主要用于報表的顯示
Report:報表,以rdlc結尾的文件,可視化設計報表模板。
報表數據:內置字段,參數,圖像,數據集(本報表主要使用參數,和數據集)
ReportParameter:使用名稱和值實例化新的報表參數
ReportDataSource:報表的數據源與DataTable對象聯系起來
效果圖如下:
相關代碼如下:
/// <summary> /// 設置報表 /// </summary> private void SetReport() { //第一步:清除之前的數據 this.rptView.LocalReport.DataSources.Clear(); //第二步:指定報表路徑 this.rptView.LocalReport.ReportPath = "Report2.rdlc"; //第三步:構造新的DataTable DataTable dt = new DataTable("DataTable1"); dt.Columns.Add("Name"); dt.Columns.Add("Score"); dt.Columns.Add("Id"); dt.Rows.Add(new object[] { "語文", 80, "Y0001" }); dt.Rows.Add(new object[] { "數學", 75, "S0001" }); dt.Rows.Add(new object[] { "英文", 96, "E0001" }); //名稱不能寫錯,和報表中的數據集名稱一致 ReportDataSource rdsItem = new ReportDataSource("DataSet1", dt); //此處可以有多個數據源 this.rptView.LocalReport.DataSources.Add(rdsItem); //第四步:構造參數 List<ReportParameter> lstParameter = new List<ReportParameter>() { new ReportParameter("Title",this.txtTitle.Text), new ReportParameter("Id",this.txtId.Text), new ReportParameter("Name",this.txtName.Text), new ReportParameter("Age",this.txtAge.Text), new ReportParameter("Sex",this.txtSex.Text), new ReportParameter("Salary",this.txtSalary.Text), new ReportParameter("Depart",this.txtDepart.Text) }; this.rptView.LocalReport.SetParameters(lstParameter); this.rptView.ZoomMode = ZoomMode.Percent; this.rptView.ZoomPercent = 100; //第五步:刷新報表 this.rptView.RefreshReport(); }
關于ReportViewer生成報表就分享到這里了,解決問題并不止文章中和大家分析的辦法,不過本文分析的方法準確性是不容置疑的。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。
分享文章:ReportViewer生成報表的相關代碼
網站URL:http://m.2m8n56k.cn/article32/iesdsc.html
成都網站建設公司_創新互聯,為您提供ChatGPT、動態網站、定制網站、網站導航、搜索引擎優化、自適應網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯