本人在闲暇之余帮朋友做了个软件,是关于考古方面的。先上图,
界面效果一般般,能过的去就行了,今天我主要说的是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