Use .net object as data source in Crystal Report 2008

浪尽此生 提交于 2019-12-02 03:04:38

问题


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.....


回答1:


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).



来源:https://stackoverflow.com/questions/1818449/use-net-object-as-data-source-in-crystal-report-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!