c#报表出现“尚未为数据源提供数据源实例”解决办法

来源:互联网 发布:刘一龙 知乎 编辑:程序博客网 时间:2024/05/01 23:38

c#报表出现“尚未为数据源提供数据源实例”解决办法

2009年12月10日 myjang 发表评论 阅读评论

1、rdlc文件时一个文本文件(只不过vs设计器打开时,是可视化的),用文本编辑器打开查看,有dataset节点,如下所示,<DataSet Name=”HBQueue_JgdmBean”>,当然,dataset节点可以有多个,没用的可以删除,删除前注意备份,也要确保删除无误。记住dataset名字。

2、问题出现在form的designer文件中(vs2005以上),不用设计器打开,用文本打开form.designer.cs文件,查看代码,在InitializeComponent方法中有类似如下代码

Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
系统自动添加的代码,如果中间改过名字,上述部分可能会出现多个dataSource,

Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();

3、再往下看,有如下类似代码

reportDataSource1.Name = “HBQueue_JgdmBean”;
            reportDataSource1.Value = this.JgdmBeanBindingSource;

reportDataSource2.Name = “PrintClient_JgdmBean”;
            reportDataSource2.Value = null; 

            reportView1.LocalReport.DataSources.Add(reportDataSource1);

reportView1.LocalReport.DataSources.Add(reportDataSource2);
问题就出现在上面的代码中,在此不多做解释了,自行处理,则问题解决。

数据传输打通的桥梁也就在这儿了。

4、上面的JgdmBeanBindingSource很简单了,就是一个数据源绑定对象,设定好DataSource属性,即通过vs新建的数据源,一般来说,用数据对象的居多。

5、问题解决的关键就在第2点和第3点。