Reports with Crystal Reports

Reports with Crystal Reports

Old forum URL: forums.lhotka.net/forums/t/2248.aspx


georgeb posted on Wednesday, January 31, 2007

Has anyone created a report using crystal reports and CSLA without using a dataset but directly from the BO? I have put the report in my library of a web project and put the crystalviewer on an asp page allong with a CRdatasource control pointing to the report in the library. It does not work!(asks for connection details to the database). Probably I am doing something terribly wrong. I am using VS 2005 and CR XI R2 SP1. Any suggestions or help are more than welcome!!

Michael Hildner replied on Wednesday, January 31, 2007

George,

I've done Crystal Reports directly off of BO's, although in a Windows Forms app and not a web project.

When I've seen Crystal ask for the database login, it was because I didn't set the data source of the report via .SetDataSource(). I figured Crystal was asking where to get the data because it wasn't handed any.

Not sure if that's your issue though.

Mike

georgeb replied on Wednesday, January 31, 2007

Thank you for your suggestion but I am still confused. In my library I have a messageRPT.rpt file which as a database field has the BO a root object containing childs. Then on an ASP page I place a crystallReportViewer and  a crystalReportSource pointing to the messageRPT file. It is not clear where to pass the actual data (BO) to the report. It does not accept directly the BO as a datasource?

Michael Hildner replied on Wednesday, January 31, 2007

Here's some code I have - never done it in a web app, but I'm guessing it's similar. Hope it helps anyway.

// ReportForm is a windows form that contains a Crystal

// report viewer.

ReportForm rf = new ReportForm();

rf.Text = "Order Report";

 

// OrderHeaderReport is a Crystal ReportClass.

OrderHeaderReport report = new OrderHeaderReport();

 

// Set the viewer's report source to our report.

rf.crystalReportViewer1.ReportSource = report;

 

// Get the data. OrderHeader is a Csla.ReadOnlyListBase.

OrderHeader order = OrderHeader.GetOrderHeader(_orderHeader.PK);

           

// Set the report's data to our business object.

report.SetDataSource(order);

           

rf.WindowState = FormWindowState.Maximized;

rf.Show();

 

 

georgeb replied on Wednesday, January 31, 2007

Thanks for the steps, the confusion remains I have written the following code

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Imports Secretary.Library

Partial Class MessagesRPT

Inherits System.Web.UI.Page

Private messagesReport As New MessagesRPT   'that is the report

Dim businessObject As Secretary.Library.Subscriber

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

businessObject = Session("currentObject")

myCrystalReportViewer.ReportSource = messagesReport

//The problem is that the messagesReport does not show the method SetDataSource. Instead it show a private method ob businessobject. That is what confuses me.

End Sub

End Class

 

Michael Hildner replied on Wednesday, January 31, 2007

What does "MessagesRPT" derive from? I guess it's not a CrystalDecisions.CrystalReports.Engine.ReportClass?

 

Michael Hildner replied on Wednesday, January 31, 2007

Oh, looking at your code again, MessagesRPT is your web form, not the Crystal Report you designed, right?

georgeb replied on Wednesday, January 31, 2007

No, it is the Crystal Report I designed

georgeb replied on Wednesday, January 31, 2007

I used the same name and that confused the system. I changed the name and now I get the data source name is invalid but I get the method to set the datasource.

Michael Hildner replied on Wednesday, January 31, 2007

Can you post more details regarding "the data source name is invalid "? Maybe the code and whether it's a compile-time or run-time issue.

georgeb replied on Wednesday, January 31, 2007

Michael, thank you very much!!!! I found the answer you gave for the last error in http://forums.lhotka.net/forums/thread/9081.aspx .As you state there it needs a List or a collection. So to finalize this your steps work fine and the object passed to the report must be a collection or a list. The overall process simplyfies the report creation with CSLA and crystal reports.

Michael Hildner replied on Wednesday, January 31, 2007

Oh, I think I've seen this before - does the exception say "The data source object is invalid."?

If that's the case, it could be because you're passing in an object in .SetDataSource() that Crystal doesn't like. I think the Crystal documentation is a little out of whack. Intellisense doesn't show an overload that takes a type of object, but you can pass in any object. The documentation doesn't show that an overload takes a type that implements IEnumerable, but that's what you pass in, so it would have to be a ReadOnlyList or something else that implements IEnumerable.

Even if you have only one object for your report, you need to wrap it in something that implements IEnumerable.

 

Michael Hildner replied on Wednesday, January 31, 2007

Heh, little late on that last response.

Glad you got it figured out.

georgeb replied on Wednesday, January 31, 2007

It is the name of the report in the library

Copyright (c) Marimer LLC