SSRS (4-1) --- Crystal Reports for VS 2022

Note: this article is published on 08/29/2024.

This series of articles will discuss SQL Server Reporting Services, including the related Services:

A - Introduction

The services discussed include:

  • SSIS --- SQL Server Integration Services
  • SSAS --- SQL Server Analysis Services
  • SSRS --- SQL Server Reporting Services
  • SSDT --- SQL Server Data Tools

This article actually is not related to any of SQL Server service, but a report from Crystal Reports that is from Seagate Technology as early as in 1994. I put it here because:

  • It is a report;
  • It is a Database, say, SQL Server reporting tool.
  • It has similar installation or running process as SSRS.

These three features make Crystal Reports iin this article series. The content of this article will be

  • A - Introduction
  • B - Installation
  • C - Create a Visual Studio Project
  • D - Create a Crystal Report
    • D -1, Crystal Report Gallery
    • D - 2, Standard Report Creation wizard
  • E - Crystal Report Viewer Control.
  • F - Bind Report to Crystal Report Viewer Control
  • G - Run the Report

B - Installation

The integration between Crystal Report and Visual Studio is a bit different from SSRS integrated with Visual Studio. For SSRS (SSDT), only one piece of software, we call it as SDK, needs to be installed and most likely as an extention of Visual Studio. They are tightly integrated to each other because they are both Microsoft Products. For crystal report, it is belong to SAP, we need to download and install two pieces of software:

The integration with Visual Studio is not seamless. First, the installation information is quite hard to obtain. We finally got it from this article, with below info:

Steps to Follow:

  1. Uninstall all the SAP Crystal Reports versions.
  2. Completely close the Visual Studio (end task from task manager).
  3. Download the SAP Crystal Report Developer Edition. Unzip and run the executable file.
  4. Download SAP Crystal Reports Runtime Engine 64 bits or 32 bits as per the system requirement and run as administrator.
  5. Ready to use the crystal report in Visual Studio 2022.

We follow this, and success.

Note:

The point is when SSRS integrated with Visual Studio, all .Net related conponents are installed, so only the piece of extension is needed to be installed. However, for Crystal Reports, your machine might have nothing on it, so installing the Crystal Reports itself is a must. That is why we need to install two pieces of softwares.

B - 1, Download and Install SAP Crystal Report Developer Edition:

The downloaded installer:

Start installation:

Choose language:

SAP Crystal Reports, Version for Microsoft Visual Studio 64 bit:

License:

Start installation:

Processing:

Done. 

Note:

We have installed the SAP Crystal Reports, version for Microsoft Visual Studio --- 64-bit. We will install the its Run Time Engine 64-bits later on, because I have a 64-bit machine, and also 64-bit Visual Studio 2022. However, in the last step of the installation of SAP Crystal Reports above, there is a choice: 

We have to choose YES.  Otherwise, we will get some other issue that i will state later on.

B - 2, Download and Install SAP Crystal Reports Runtime Engine 64 bits

The downloaded installer:

unzipped:

SAP Crystal Reports Runtime Engine for .NET Framework 64-bit

Licensing:

Start installing:

Process:

done

C - Create a Visual Studio Project

We use the current version of Visual Studio 2022 17.11.2 and .NET Framework 4.8.1 --- the latest .Net Framework version, to build the app (I did not try the .Net Core).

Create a Window Forms App for .Net Framework,

such as:

named as CrystalReports:

The app is opened:

D - Create a Crystal Report

  • Right Click the Project => Add New Item. This displays the list of available templates.
  • Select Reporting Template Group.
  • => Select the Crystal Report template.

  • Enter the name as  EmployeeList.   

Click on Add to Create your first Report. This will take you to Crystal Report Gallery.

D -1, Crystal Report Gallery

Report Wizard

  • Using a Report Wizard.  
    Selecting this option will open the crystal report wizard which takes you through the various steps to help you in creating the report.
  • As a blank Report.     
    This will open a blank report.
  • From an Existing Report.   
    Here you are asked to select an existing report and the new report use.

Report Expert.

Crystal Report for Visual Studio comes with three report Experts.

  • Standard Format.
    This expert will create the standard report.
  • Cross Tab. 
    This expert will create a specialized report known as cross tab report.
  • Mail Label. 
    This expert will create mailing label report where data is displayed in a format that is suitable for use as address labels on envelopes.

In this example let us select Report Wizard and Standard Expert and then click on next. You will be taken to the Standard Report Creation wizard.

D - 2, Standard Report Creation wizard

First dialogue box under this allows you to choose the data source that would be used in the report.  It has three options

  1. Project Data.  
    This Option lists the data source connections already available in your project.
  2. My Connections.   
    This Option lists the most recently used data source connection so that you can quickly add it your report.
  3. Create New Connection.
    This Option allows us to create a new connection to data source.

Let us Select OLE/DB option to connect to our data source.  click on the plus sign right next to OLE/DB option. This will open the OLE/DB Dialog Box.

OLE/DB Dialog Box.

This Dialog Box Option displays the list of available OLE/DB Providers. Choose the appropriate OLE/DB Provider to connect to your data source.
Let us chose Microsoft OLE DB Driver for SQL Server which is used to connect to the SQL Server Database. Click on next. 

OLE/DB Connection Info Dialog Box.

You will then see OLE/DB Connection Info Dialog Box. Here you need to input the database credential to connect to the data source.

Input server Name. You can either input the user id and password or choose Integrated security option. If you choose User id and password, then the crystal report will ask you for user id & Password while displaying the report.  I will choose Integrated security.

Select the database from the drop-down. select northwind database. Click on next when you are done.

OLE/DB Advance Information Dialog Box

You will then see OLE/DB Advance Information Dialog Box. Make appropriate changes if any and click on Finish to go back to Standard Report Creation wizard.

Standard Report Creation wizard

Northwind data connection we just made is displayed under OLE/DB option under Create the new connection. 

Click on plus sign to expand to the database.  Any Tables, Stored Procedures, Views under the selected data source connection is automatically displayed under the connection and is available to the report. Select the appropriate the table/Stored Procedures/View which you want in your report.

  • Select employees table.
  • Click right arrow key to add the table to the report.

The table will appear in the selected tables box on the right side. You can add more than one table to report. Click on next. You will be taken to Fields Dialog box.

Fields Dialog Box.

On the left  side, you can see the list of fields from the employee table. These fields are now available to the report.   You can select any field just by double-clicking on them. Selected fields will appear on fields to display box on the right side.

Select any field on the left side box and click on browse data and view the database values of the selected field.

  1. Select FirstName, LastName, Title, Address, City.
  2. You can then click on right arrow key to add the fields to the report.
  3. The fields will appear on the right side box.
  4. You can move the field up and down by dragging the fields or using up or down arrow buttons.
  5. Place the fields in the order you want them to appear in the Report.
  6. Click on finish. You will then see the crystal report designer and the report is generated for you.

E - Crystal Report Viewer Control.

The next step is to show the crystal report in our windows form. To do this, you need to add Crystal Report Viewer control to the form.  CrystalReportViewer Control is a usercontrol class and can be used as any other user control class. Primary Function of is to Display Reports.

  1. Open the form frmcrystalreport which we have created.
  2. Locate Reporting tab in the toolbox.
    CrystalReportViewer control is listed under the Reporting Tab in the toolbox. So go to the toolbox and locate the reporting tab.
  3. Select the crystalReportViewer drag and drop it unto the form.

Now we have added the control.

F - Bind Report to Crystal Report Viewer Control

  1. Open frmCrystalReport.  
  2. Go to the Properties Window => Event => double click Load:

  • Open the form load event and write the following code to bind the Crystal Report to the data:

G - Run Your First Report

  • Buyild and Run the app

Note:

When I ran the app, even everything is just OK, and buildable, but I got the error message like this

This is not debugable. Search online, I found out an answer, that when I installed the SAP Crystal Reports, there is a choice to ask you: if you want to install the Crystal Reports Runtime, 32-bit, you have to select that option. Then eveything is working good. The info I got is from this article: 

 

References:


Similar Articles