开发者

Using Crystal Reports with a C# Object

I am new to Crystal reports. I need to build a Report but don开发者_如何学编程't have access to Data Source. The reports need to be populated with a .Net Class containing a List of Data. How can i do this. I have been searching on Google most of the day but can only find examples of using a SQL or ADO.NET data source. How can i do this using a Class Object with a List in C#.

Kind Regards.

Mateen


We can use .Net Class as a DataSource For Crystal Report While Adding Crystal Report it will ask for Ad0.Net or .Net Object. In that we have to Choose .Net Objects. it would list all the classes in your project. in That we can choose the class which we want to use it as a datasource. Then the properties of the Class will be listed and in that we can choose the necessary fields

Here is the Sample Code:

Dy_Daywisesales_RPT myDataReport = new Dy_Daywisesales_RPT();

// This is to get the individual textobject
(myDataReport.Section2.ReportObjects["txtFromDate"] as TextObject).Text=Daywisesales.From1;
(myDataReport.Section2.ReportObjects["txtToDate"] as TextObject).Text=Daywisesales.To1;
(myDataReport.Section2.ReportObjects["txtStation"] as TextObject).Text=Daywisesales.StationName;

// This is the collection as a datasource
myDataReport.SetDataSource(Daywisesales.lstDayWiseSalesDetails);
crystalReportViewer1.ReportSource = myDataReport;


Reports need a data source. You may be able to serialize the list of data in the .Net class to an XML file, comma delimited file, or some sort of data structure that crystal reports can connect to and then use.

I don't think you can connect directly to a .Net class and "report" on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜