使用.NET对象作为数据源,在2008水晶报表 [英] Use .net object as data source in Crystal Report 2008

查看:267
本文介绍了使用.NET对象作为数据源,在2008水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个.NET对象(例如: A ),它包含数据已收集表。 接下来,我创建了一个名单,其中,A>(),并传递给的setDataSource()的方法的ReportDocument 对象。 当我运行,那么一个异常被扔:

 CrystalDecisions.CrystalReports.Engine.DataSourceException:数据源对象是无效的
 

我不知道上述异常,错误消息不明确。任何人都可以解释给我吗?例如:在.NET对象必须继承ISerializable的......

解决方案

我有同样的错误,但使用对象作为数据源的报表时遇到了它

。我有以下code:

  VAR MyObj中=新MyDataObject();
cr.Load(@C:\ report.rpt);
cr.SetDataSource(MyObj中);
 

和得到了同样的错误。

更改的setDataSource行这样的:

  cr.SetDataSource(新[] {MyObj中});
 

帮助,并且它现在正常工作。 换句话说,尝试包装你的对象在数组中。如果您使用的是列表,首先尝试转换到一个数组(使用.ToArray()方法)。

HI all,

I created a .net object (ex: A) which contain data have been collected from tables. Next, i create a List<A>() and pass to SetDataSource() method of ReportDocument object. When i run then an Exception have been throwed :

"CrystalDecisions.CrystalReports.Engine.DataSourceException: The data source object is invalid"

I don't know the Exception above, Error message isn't clear. Can anybody explain for me? ex: the .net object must inherit from ISerializable.....

解决方案

I had this same error, but encountered it when using an object as the data source for the report. I had the following code:

var myObj = new MyDataObject();
cr.Load(@"C:\report.rpt");
cr.SetDataSource(myObj);

and got the same error.

Changing the SetDataSource line to this:

cr.SetDataSource(new [] { myObj });

helped and it is now working correctly. In other words, try wrapping your object in an array. If you're using a list, try converting it to an array first (use the .ToArray() method).

这篇关于使用.NET对象作为数据源,在2008水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆