RDLC報表使用問題及解決方案


本人在閑暇之余幫朋友做了個軟件,是關於考古方面的。先上圖,

界面效果一般般,能過的去就行了,今天我主要說的是RDLC開發過程中容易出錯的地方,我這里封裝了一個RDLC調用方法:

 1  /// <summary>
 2     /// RDLC報表打印類
 3     /// </summary>
 4     public class RDLCReportHelper
 5     {
 6       public static  ReportDataSource reportDataSource = null;
 7        public static BindingSource bindingSource = null;
 8         /// <summary>
 9         /// 展示報表
10         /// </summary>
11         /// <param name="rv">展示報表的容器</param>
12         /// <param name="ds">數據集</param>
13         /// <param name="p_strTableName">數據集表名</param>
14         /// <param name="p_strReportFile">報表名稱[路徑]</param>
15         public static void showReport(ReportViewer rv, DataSet ds, string p_strTableName, string p_strReportFile)
16         {
17             try
18             {
19                 rv.Reset();
20                // rv.RefreshReport();
21                 bindingSource = new BindingSource();
22 
23                 bindingSource.DataSource = ds;
24                 bindingSource.DataMember = p_strTableName;
25                 //實例化報表數據源
26                 reportDataSource = new ReportDataSource();
27                 //數據源名稱[數據集名_表名]
28                 reportDataSource.Name = ds.DataSetName + "_" + p_strTableName;
29                 //封裝綁定的數據集給報表數據源
30                 reportDataSource.Value = bindingSource;
31 
32                 //加載報表數據源
33 
34                 rv.LocalReport.DataSources.Clear();
35                 rv.LocalReport.DataSources.Add(reportDataSource);
36                 //指向本地報表
37                 //rv.LocalReport.ReportEmbeddedResource = p_strReportFile;
38                 rv.LocalReport.ReportPath = Application.StartupPath+"\\"+p_strReportFile;
39                 rv.SetDisplayMode(DisplayMode.PrintLayout);
40                 rv.ZoomMode = ZoomMode.Percent;
41                 //顯示[刷新]報表數據
42                 rv.RefreshReport();
43 
44                 bindingSource = null;
45                 reportDataSource = null;
46             }
47             catch (Exception ex)
48             { 
49             
50             }
51          
52         }
1、代碼中的rv.reset();這句話 很重要 ,如果沒有這一句話,動態切換顯示不同的報表的時候,會出錯。
2、rv.localReport.reportPath=......  這里面要給reportView傳遞全路徑的rdlc文件,否則會找不到相應的rdlc文件而報錯。
3、在調試rdlc報表的時候報檢測到 PInvokeStackImbalanceMessage: 對 PInvoke 函數“Microsoft.ReportViewer.Common!Microsoft.ReportingServices.Rendering.ImageRenderer.CompositionPDF+WindowsGDIWrapper::GetGlyphIndicesW”的調用導致堆棧不對稱。 這種錯誤,但是在發布之后的程序是沒有問題的,這種錯誤可以不用理會。
4、調用方法如下:
 ds = new DataSet();
            String whereSql;
            if (this.cbType.Text == "器材列表") {
                ds = b_device.getDataSetDevice();
                ds.DataSetName = "DataSet_device";
                ds.Tables[0].TableName = "device";
                Utils.RDLCReportHelper.showReport(this.reportViewer1, ds, "device", "RDLC\\Report_qicai.rdlc");
            }

我說的只是對rdlc使用過程中容易出現的問題,本人也是對rdlc第一次使用,希望和大家一起交流,共同進步。    到此為止  thanks

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM