Use a .net object as a data source in Crystal Report 2008

Hi all,

I created a .net object (ex: A ) that contains data collected from tables. Then I create a List<A>() and pass the SetDataSource() method of the SetDataSource() object. When I run, the exception was thrown:

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

I do not know the above exception, the error message is not clear. Can someone explain to me? ex: the .net object must inherit from ISerializable .....

+2
source share
1 answer

I had the same error, but I encountered it when using the object as a 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 as follows:

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

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

+4
source

Source: https://habr.com/ru/post/888923/


All Articles