解决Stimulsoft Reports.Net中重做相同报表但没有结果的问题

作者:cheny    来源:Stimulsoft中文网    浏览:Loading...      日期:2013-07-05

Stimulsoft Reports.Net重做相同的报表有时候会出现没有结果的问题,尽管我们尝试去修改一些参数,但是问题最终还是无法解决。

今天遇到个实例和大家分享下。

一、第一此做报表时,报表已经有私有变量了,代码如下:
                     string reportToLaunch = Path.Combine(@"c:\path", "report.mrt");

                    _CostificationMOReport = new StiReport();
                    _CostificationMOReport.Load(reportToLaunch);
                    _CostificationMOReport.Compile();

二、之后{Compile()},我加入链接数据源参数:
_CostificationMOReport.DataSources["MyDS"].Parameters.Clear();
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Clear();

_CostificationMOReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "1", 22, 50));
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "1", 22, 50));


三、最后,渲染,给报表查看器赋值:
CostificationMOReport.Render(false);

_viewer.Report = _CostificationMOReport;

四、我在调用相同报表的时候,试着避免重编MRT,如下:
//clear pages
_viewer.Report =null;
_CostificationMOReport.CompiledReport.RenderedPages.Clear();

//clear old parameters
_CostificationMOReport.DataSources["MyDS"].Parameters.Clear();
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Clear();

//inject new parameters
_CostificationMOReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "2", 22, 50));
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "2", 22, 50));

//render
_CostificationMOReport.Render(false);

//re-assign to report viewer
_viewer.Report = _CostificationMOReport;

//I tried even this, but doesn't work
// _CostificationMOReport.ViewerControl = _viewer;
// _CostificationMOReport.Show();
// _CostiticationMOReport.InvokeRefreshViewer();

问题就出现在这里了,报表老是显示以前的东西,改了好久,都没有解决。

五、最后不得不找度娘谷歌,终于是找到了点头绪,发现写得太过于复杂,很简单几步就可以,搞定的,也不需要清除参数,代码如下:
StiReport rep = new StiReport();
rep.Load("Report.mrt");
rep.Compile();
rep["Par1"] = 5;
rep.Render();
rep.Show(true);
rep["Par1"] = 7;
rep.Render();
rep.Show(true);

就这么简单解决了。

在这里点击下载Stimulsoft Reports.Net,一起分享使用经验

Tag标签:Stimulsoft Reports,报表 

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:Stimulsoft中文网 [http://www.Stimulsoft.cn/]
本文地址: http://www.Stimulsoft.cn/Resources/doc/175.html

上一篇: 如何用Stimulsoft Reports.Fx for Java创建Web报表

下一篇: 如何禁用自定义函数水印