Crystal Reports Without Database in C#

This article provides an idea of how to use Crystal Reports without a database. We are using Crystal Reports to featch data from a database and show it in a report. Here we are generating a Crystal Reports report without using a database. For this we used a Strongly Typed Dataset and a Data Table of C#.

If you are new to Crystal Reports and do not know how to create Crystal Reports reports from C# then please have a look at the section:

Use the following procedure to generate s Crystal Reports report without a database in C#.

Generating a Strongly Typed Dataset

1. Create a new Windows Forms application and add a Button.
2. Then right-click on the project in Solution Explorer and click "Add" -> "New Item...".
3. Select Dataset like following :

Dataset

Then name it as you wish to Dataset.

4. Create a Datatable for the Dataset. For that select a recently added Dataset and right-click. add a new DataTable from this as in the following:

Datatable for Dataset

Then you will get the DataTable in that Dataset as in the following:

DataTable in Dataset

5. Right-click on that added DataTable and select "Add" -> "Column".

ADD New Column

DataTable

Here we add two columns one LanguageId and the other is LanguageName. Now the Dataset part is over, the next step is to create a Crystal Reports report from the DataSet we created.

6. Add a new Crystal Reports report from the Add New Item Menu and accept the default settings. Then the next screen is to select an appropriate data source, there you can find the DataTable1 we recently added to DataSet1, from the Project Data, ADO.NET Datasets and select Datatable1 to the right side.

ADD New Crystal Reports

Report Creation Wizard

Select "Next >" and add that LanguageId and LanguageName field in the right side like this:

LanguageId and LanguageName field

Now the C# Crystal Reports designer part is over. The next part is to create data for the report. For that we need to create a Data Table programmatically and add data to dataset1.

7. Select the default form (Form1.cs) you created in C# and a CrystalReportViewer control to your form, it will display like this:

CrystalReportViewer control

8. Now your report is ready. Run the project after clicking the Crystal Reports Button, it will show you the report as in the following:

Crystal Report Button

If you get the following error when running the application then just add the following code to your App.config file.

config file

App.config file Code :

<?xml version="1.0"?>

<configuration>  

  <startup useLegacyV2RuntimeActivationPolicy="true">

       <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

  </startup>
</
configuration>

Conclusion

In this article we learned how to create a Crystal Reports without a database in C#. I hope this example will help you to learn the basics of a C# Crystal Reports application and how to create a Crystal Reports report without a database.Thanks for reading.


Similar Articles