Using Crystal Reports with a C# Object - c#

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.

Related

Single RDLC file to populate any type of custom object passed to it

I have a list of stored procedures which return different types of object (with varying column) to my business layer. Also, I created a single RDLC file named allreports.rdlc in my mvc application and put it in some .cshtml page.
Now, I want to call any of the stored procedure (based on user input passed as query parameter to my controller) and retrieve data in dataset (or any better format if available) and want to pass it to my rdlc report.
Can I achieve this using a single rdlc file which will be used to populate my any of the stored procedure dataset results. Also, please suggest if there is any other approach to achieve this?
Goal: To integrate all the reports in a single report page by changing underlying data formats. I don't want to make my application releases for each new report requirement by changing the underlying codes.
If any more clarification is needed; let me know instantly so that I could search the solution for it.
Syncfusion.EJ.ReportViewer library can dynamically create RDL reports in code behind by using ReportDefinition object. Please refer to sample that populates Tablix report item based on Datatable columns.
Sample Link
The whole product is available for free through the community license if you qualify (less than 1 million USD in revenue).
I work for Syncfusion.

Visual Studio 2013 - Creating Dataset for RDLC Report

I am trying to make a report. The class that I am working with has several ICollection properties, and passing those values to the report for display is difficult.
I have created a class called FlatClass that has all of the string values that I need to display. In the Controller, I plan to populate an array of type FlatClass and pass it to my Report. From what I have read, I need to create a custom dataset/data source. In Visual Studio 2013, when I click Add DataSet in the Report Data tab, it wants me to choose a table from my database. But ClassFlat does not have a table in the database.
I have added a .xsd file, but I cannot find any instruction on how to tell it the names and types of the Fields I want it to have.
Any help would be greatly appreciated!!!!
I tried to create rdlc report in my web application but I could not add my class as dataset. There was no option for that.
Workaround:
Create a Library project in the same solution.
Add the main project as reference to this new Library project.
Create a rdlc file.
Add dataset; for datasource select New->Object->Choose the class from you project namespace
Do your report and when it is complete, move the file to the main project
Not sure if your problem is similar but hope the information is useful.
I ended up creating an .xsd file and just editing the raw XML to add all the properties of the class I wanted to use as a dataset. This worked when I added it to the report.

RDLC Reports - I can only specify a database data source rdlc report

Problem looks like this:
I have web application and when I create new report.rdlc I can only specify a database data source rdlc report. Do you have idea why I can't create new data source from object?
1.Please refer the following documentation for using a Business Object Data Source.
http://msdn.microsoft.com/en-us/library/ms251692%28v=vs.100%29.aspx
2.Also you can add using external class library,to do this follow the steps.
Create a class library with property, methods in a class.
Add created class library using Addreference option in the Data source configuration wizard.
Select the added class library and follow the steps provided in the Walkthrough.
Thanks,
Anandakumar S

Crystal Report Database Fields doesn't display classes from a referenced project

I created a website and a class library project. The website have a reference to a class library.
I added a new Crystal Report item to the website (CrystalReport.rpt), and on the Database Expert screen, in the Database Fields section I need to select fields that are members of classes in the class library (referenced project). Only the website classes appear in the list.
Is there a way to do this?
Thanks.
I've had this problem before, in order to see the DB fields, I had to create the XSD even if I had to populate a dataset and pass it along once in design time (debugging) . Try doing so before adding the rpt file.

Using Crystal Reports in Visual Studio 2005 (C# .NET Windows App)

I need to create reports in a C# .NET Windows app. I've got an SQL Server 2005 database, Visual Studio 2005 and am quite OK with creating stored procedures and datasets.
Can someone please point me in the right direction for creating reports? I just can't seem work it out. Some examples would be a good start, or a simple How-to tutorial... anything really that is a bit better explained than the MSDN docs.
I'm using the CrystalDecisions.Windows.Forms.CrystalReportViewer control to display the reports, I presume this is correct.
If I'm about to embark on a long and complex journey, what's the simplest way to create and display reports that can also be printed?
I have managed to make this work now.
Brief Overview
It works by having a 'data class' which is just a regular C# class containing variables and no code. This is then instantiated and filled with data and then placed inside an ArrayList. The ArrayList is bound to the report viewer, along with the name of the report to load. In the report designer '.Net Objects' are used, rather than communicating with the database.
Explanation
I created a class to hold the data for my report. This class is manually filled by me by manually retrieving data from the database. How you do this doesn't matter, but here's an example:
DataSet ds = GeneratePickingNoteDataSet(id);
foreach (DataRow row in ds.Tables[0].Rows) {
CPickingNoteData pickingNoteData = new CPickingNoteData();
pickingNoteData.delivery_date = (DateTime)row["delivery_date"];
pickingNoteData.cust_po = (int)row["CustomerPONumber"];
pickingNoteData.address = row["CustomerAddress"].ToString();
// ... and so on ...
rptData.Add(pickingNoteData);
}
The class is then put inside an ArrayList. Each element in the arraylist corresponds to one 'row' in the finished report.
The first element in the list can also hold the report header data, and the last element in the list can hold the report footer data. And because this is an ArrayList, normal Array access can be used to get at them:
((CPickingNoteData)rptData[0]).header_date = DateTime.Now;
((CPickingNoteData)rptData[rptData.Count-1]).footer_serial = GenerateSerialNumber();
Once you have an arraylist full of data, bind it to your report viewer like this, where 'rptData' is of type 'ArrayList'
ReportDocument reportDoc = new ReportDocument();
reportDoc.Load(reportPath);
reportDoc.SetDataSource(rptData);
crystalReportViewer.ReportSource = reportDoc;
Now you will need to bind your data class to the report itself. You do this inside the designer:
Open the Field Explorer tab (which might be under the 'View' menu), and right-click "Database Fields"
Click on 'Project Data'
Click on '.NET Objects'
Scroll down the list to find your
data class (if it isn't there,
compile your application)
Press '>>' and then OK
You can now drag the class members
onto the report and arrange them as
you want.
Crystal is one possible option for creating reports. It has been around a long time and a lot of people seem to like it.
You might want to take a look at SQL reporting services. I have used both but my preferance is SQL reporting services. Its pretty well integrated into studio and works similar to the other microsoft projects. Its also free with the sql express etc.
This is a good article on beginning reporting services:
http://www.simple-talk.com/sql/learn-sql-server/beginning-sql-server-2005-reporting-services-part-1/
You can use the report viewer with client side reporting built into vs.net (ReportBuilder/ReportViewer control). You can create reports the same way as you do for sql reporting services, except you dont need sql server(nor asp.net). Plus you have complete control over them(how you present, how you collect data, what layer they are generated in, what you do with them after generating, such as mailing them, sending to ftp, etc). You can also export as PDF and excel.
And in your case building up a report from data and user input, this may work great as you can build up your own datasource and data as you go along. Once your data is ready to be reported on, bind it to your report.
The reports can easily be built in Visual Studio 2005 (Add a report to your project), and be shown in a Winforms app using the ReportViewer control.
Here is a great book i recommend to everyone to look at if interested in client side reports. It gives a lot of great info and many different scenarios and ways to use client side reporting.
http://www.apress.com/book/view/9781590598542
I second alex's recommendation to look at sql reporting services - if you have a sql developer license, then you probably already have reporting services
i don't like crystal reports, too much tedium in the designer (editing expressions all the time) too many server-deployment issues (check those license files!)
I use Crystal. I will outline my method briefly, but be aware that I'm a one man shop and it may not translate to your environment.
First, create a form with a CR Viewer. Then:
1) Figure out what data you need, and create a view that retrieves the desired columns.
2) Create a new Crystal report using the wizard giving your view as the source of the data.
3) Drag, drop, insert, delete, and whatever to rough your report into shape. Yes, it's tedious.
4) Create the necessary button click or whatever, and create the function in which to generate the report.
5) Retrieve the data to a DataTable (probably in a DataSet). You do not have to use the view.
6) Create the report object. Set the DataTable to be the DataSource. Assign the report object to the CR Viewer. This is one part for which there are examples.
Comments:
If you lose the window with the database fields, etc (Field Explorer), go to View/Document Outline. (It's my fantasy to have Bill Gates on a stage and ask him to find it.)
The reason for setting up the view is that if you want to add a column, you revise the view, and the Field Explorer will update automatically. I've had all sorts of trouble doing it other ways. This method also is a work-around for a bug that requires scanning through all the tables resetting which table they point to. You want to hand Crystal a single table. You do not want to try to get Crystal to join tables, etc. I don't say it doesn't work; I say it's harder.
There is (or was) documentation for the VS implementation of Crystal on the Business Objects web site, but I believe that it has disappeared behind a register/login screen. (I could stand more info on that myself.)
I've had trouble getting Crystal to page break when I want, and not page break when I don't want, etc. It's far from the best report writer I've ever used and I do not understand why it seems to have put so many others out of business. In addition, their licensing policies are very difficult to deal with in a small, fluid organization.
Edited to add example:
AcctStatement oRpt = new AcctStatement() ;
oRpt.Database.Tables[0].SetDataSource(dsRpt.Tables[0]);
oRpt.SetParameterValue("plan_title",sPlanName) ;
crViewer.ReportSource = oRpt ;
I found the following websites solved my problems. Included here for future reference.
CrystalReportViewer Object Model Tutorials for the tutorial on how to make the whole thing work. And also Setting up a project to use Crystal Reports
and specifically preparing the form and adding the control
i think this may help you out
http://infynet.wordpress.com/2010/10/06/crystal-report-in-c/
I strongly recommend trying an alternative reporting solution - I have a lot of experience with Crystal, and have managed to do some funky things with it in .Net, but quite honestly the integration of Crystal and .Net is an absolute pig for anything but the simplest cases.
I have tried RS. I am converting from RS back to Crystal. RS is just too heavy and slow (or something). There is no reason to have to wait 30 seconds for a report to render is RS when Crystal does it in under a second.

Categories

Resources