首页 新闻 会员 周边

最近在做一个关于报表的东西,但是老是报错。在网上找了很多办法,一直都没有成功 解决,求各位大牛帮助!

0
悬赏园豆:5 [已解决问题] 解决于 2014-04-02 16:42

 

一直卡在这问题上了,找不到原因。

我在初始化中指定了报表文件地址,代码如下

this.components = new Container();
ReportDataSource reportDataSource = new ReportDataSource();
ReportDataSource reportDataSource2 = new ReportDataSource();
ReportDataSource reportDataSource3 = new ReportDataSource();
this.SSDataTableBindingSource = new BindingSource(this.components);
this.XMLDataSet = new XMLDataSet();
this.BLSYReportViewer = new ReportViewer();
((ISupportInitialize)this.SSDataTableBindingSource).BeginInit();
((ISupportInitialize)this.XMLDataSet).BeginInit();
base.SuspendLayout();
this.SSDataTableBindingSource.DataMember = "SSDataTable";
this.SSDataTableBindingSource.DataSource = this.XMLDataSet;
this.XMLDataSet.DataSetName = "XMLDataSet";
this.XMLDataSet.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
this.BLSYReportViewer.Dock = DockStyle.Fill;
reportDataSource.Value = null;
reportDataSource2.Value = null;
reportDataSource3.Name = "XMLDataSet_SSDataTable";
reportDataSource3.Value = this.SSDataTableBindingSource;
this.BLSYReportViewer.LocalReport.DataSources.Add(reportDataSource);
this.BLSYReportViewer.LocalReport.DataSources.Add(reportDataSource2);
this.BLSYReportViewer.LocalReport.DataSources.Add(reportDataSource3);
this.BLSYReportViewer.LocalReport.ReportEmbeddedResource = "NSMedicalRecords.FirstRecordPageDesign.rdlc";

求大神指导下,万分感激。

问题补充:

如果将ReportEmbeddedResource换成ReportPath,则程序报这个错

IT胡小帅的主页 IT胡小帅 | 初学一级 | 园豆:183
提问于:2014-04-02 15:05
< >
分享
最佳答案
0

最好是VS2010以上版本做。VS2008会出错。

在Form里要放ReportViewer,然后这样调用:

 1 // 定义好Report
 2 
 3 ReportViewer1.LocalReport.ReportPath ="\\Report\\XX.rdlc";
 4 
 5 LocalReport localReportQuotation = ReportViewer1.LocalReport;
 6 
 7         DataSet dsHeader = new DataSet("DataSet_Quotation");
 8         dsHeader = getHeader(quotationCode);
 9         DataSet dsEntry = new DataSet("DataSet_Entry");
10         dsEntry = getEntry(quotationCode);
11 
12         ReportDataSource rdsHeader = new ReportDataSource();
13         rdsHeader.Name = "DataSet_Header";
14         rdsHeader.Value = dsHeader.Tables[0];
15 
16         ReportDataSource rdsEntry = new ReportDataSource();
17         rdsEntry.Name = "DataSet_Entry";
18         rdsEntry.Value = dsEntry.Tables[0];
19 
20         ReportViewer1.LocalReport.DataSources.Clear();
21         localReportQuotation.DataSources.Add(rdsHeader);
22         localReportQuotation.DataSources.Add(rdsEntry);
23         ReportViewer1.LocalReport.Refresh();

我的是Webform的,Winform类似。

收获园豆:5
酱油能 | 菜鸟二级 |园豆:386 | 2014-04-02 15:45

我用的就是VS2010阿,我做的也是Winform开发。我是在这段代码报错

1 this.BLSYReportViewer.LocalReport.SetParameters(new ReportParameter[] { reportParameter });

能帮我看一下是什么问题不?万分感谢阿!

 

IT胡小帅 | 园豆:183 (初学一级) | 2014-04-02 15:51
string s = medicalRecordsContentEntity.MedicalContent.ToString();
                    XmlReader reader = XmlReader.Create(new StringReader(s));
                    XElement xElement = XElement.Load(reader);
                    SystemSettingEntity systemSettingEntity = this._SystemSettingService.GetSystemSettingEntity("HospitalName");
                    ReportParameter reportParameter = new ReportParameter("txt_bt", systemSettingEntity.Value.ToString());
                    this.BLSYReportViewer.LocalReport.SetParameters(new ReportParameter[]
                    {
                        reportParameter
                    });
                    ReportParameter reportParameter2 = new ReportParameter("zyh", xElement.Element("病案号").Value.ToString());
                    this.BLSYReportViewer.LocalReport.SetParameters(new ReportParameter[]
                    {
                        reportParameter2
                    });

 

IT胡小帅 | 园豆:183 (初学一级) | 2014-04-02 15:57

@IT白痴: 我不太写Winform,但是可以这样试试:

首先,你的rdlc报表里是使用了DataSet吧。

1.先别用程序调用,先直接在report里看看,是否运行正确。

2. 看看你的Dataset是不是对?感觉您在这里会有点问题。

酱油能 | 园豆:386 (菜鸟二级) | 2014-04-02 16:23

@酱油能: 嗯,我已经把问题搞定了。虽然不是你说的问题,但是也很感激你回复我,所以把分也给你。怎么我都发现没人来帮助新人 解决问题了呢?

IT胡小帅 | 园豆:183 (初学一级) | 2014-04-02 16:41

@IT白痴: 谢谢,其实我也不是为了分。我自己也是个菜鸟,我知道菜鸟的痛苦。有空多交流。

酱油能 | 园豆:386 (菜鸟二级) | 2014-04-02 21:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册