How to Create Crystal Report using Visual Studio

In this Visual Studio Crystal Reports tutorial, we will show you how to create Crystal reports using Visual Studio in a windows forms application. This Tutorial is created using Visual Studio 2013. You can also use Visual Studio 2010Visual Studio 2012 or in Visual Studio 2015

Requirement

For this lesson, you will need

  1. Microsoft Visual Studio 2013.
  2. SQL Server (2008 or above).
  3. SAP Crystal Reports for visual studio.

Read More
Download Crystal Reports for Visual Studio 2015
Download Crystal Reports Run time for Visual Studio 2015

Create Crystal Reports using Visual Studio

Create Crystal Report Using Visual Studio
Create Crystal Report Using Visual Studio

Create a Visual Studio Project

Create your first Crystal Report using Visual Studio Create a Project
Creating a Project in Visual Studio
  1. Open Visual Studio and create a new project.
  2. Choose C#.
    If you want to choose VB.NET you can go ahead and choose VB.NET. Designing reports with Crystal Reports is independent of the language or type of application. The steps are the same for both VB.NET & C#. For this Example, I will choose C#
  3. Choose Windows Desktop Application.
  4. Under Various Application, Template chose Windows Forms Application
  5. Enter Name of the Project as MyFirstReport. Click OK.  Visual C# Project is opened for you.
  6. Rename the form as frmCrystalReport

Create a Crystal Report

Create your first Crystal Report Add New Item

Now let us create a crystal Report. The following steps will guide you to add the new report

  1. Under Solution Explorer select your Project.
  2. Right Click and Add New Item. This displays the list of available templates. 
    Create Your First Crystal Report - Choose Crystal Report
  3. Select Reporting Template Group.
  4. Scroll down to select the Crystal Report template.
  5. Enter the name as  EmployeeList.   
  6. Click on Add to Create your first Report. This will take you to Crystal Report Gallery.

You can Create Report using the following options

Create Your First Crystal Report - 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.

Standard Report Creation wizard

Create Your First Crystal Report - 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.

Create Your First Crystal Report - OLE DB Provider

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 SQL Server Native Client 11.0 which is used to connect to the SQL Server Database. Click on next. 

OLE/DB Connection Info Dialog Box.

OLE DB Connection Information
OLE DB Connection Information

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

Create Your First Crystal Report - OLE DB Advance Information
OLE DB Advance Information dialogue 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

Create Your First Crystal Report - Database Selected

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.

Create Your First Crystal Report - Add Table to the Report
Employee Table is Selected
  1. Select employees table.
  2. 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.

Create Your First Crystal Report - Select Fields
Fields Dialog box

You can hold the control key and select multiple fields at once.

  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.
Create Your First Crystal Report - Report Created
Created Report

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.

Create Your First Crystal Report - Add CrystalReportViewer Control
Crystal Report Viewer Control
  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.

Good, now we have added the control.

Bind Report to Crystal Report Viewer Control

Create Your First Crystal Report - Add the Code
Code in form load event
  1. Open frmCrystalReport.  
  1. Go to the code-behind class.
  2. Under the form load event write the following code (Double click form header to create the event). Declare a variable rpt to hold the instance of the employeeListemployeeList is the name of the report which we have created.
    Assign this to the report source property of the crystal report viewer control. The code will look like this.

Run Your First Report

Create your first Crystal Report Report Generated
Report Generated
  1. Save the Project.
  2. Run the project.

Congratulations you have created your first crystal report

NOTES

If you have not selected Integrated security when creating the data source you may be prompted for the database user id and password. Just enter the user id and password to see the report.

Downloads

  1. Northwind database: Northwind.bak
  2. Source code : MyFirstReport

15 thoughts on “How to Create Crystal Report using Visual Studio”

      1. I have installed crystal report sp34 for VS 2022 but its not showing up. Can you please guide me on this. Thanx in advance.

  1. Hi, I have prob in my vs. I’m using vs 2017. An exception of type ‘CrystalDecisions.CrystalReports.Engine.LoadSaveReportException’ occurred in CrystalDecisions.ReportSource.dll but was not handled in user code

  2. hi, I got some error. I’m using vs 2015. Can you help me? Thanks

    Error Report:
    An exception of type ‘CrystalDecisions.CrystalReports.Engine.LoadSaveReportException’ occurred in CrystalDecisions.ReportSource.dll but was not handled in user code

  3. Dear Friend,
    I Have Installed Visual Studio 2015 Enterprise 32 bit and downloaded crystal report and run-time both 32 and 64 bits
    but as I click on crystal report viewer in toolbox to add it into the form it all ways give me this message :
    Failed to create component ‘Crystal Report Viewer’. the error message follows:
    ‘System.Runtime.InteropServices.COMExeption(0x8004D745): A reference to the component ‘Crystal Decisions.Windows.Forms’ already exists in the project.
    at VSLangProj.Reference.Add(String bstrPath)
    at
    …..
    at

  4. Hi,

    I am using this tutorial to learn how to create Crystal Reports using Visual Studio 2010.
    I know SAP Crystal Reports (stand alone version) quite well, but this is my first experience with CR for VS.

    I have successfully downloaded the files you recommend.

    I have successfully created the Crystal Report shown in the example.

    But I cannot add the Crystal Report Viewer.

    In fact I don’t see it in the toolbox:
    I see “ReportViewer”, but not “Crystal Report Viewer”.

    What has gone wrong?

    There are build errors and it seems some references relating to “CrystalDecisions” are missing.

    What references are missing and how can I add them?

    Thanks
    Leon

    1. Added:

      When I work in C#, I can see the Crystal Reports Viewer in the Toolbox, provided I select .NET Framework 4 in the form properties.

      But if I work in VB.NET, I cannot see the Crystal Reports Viewer.
      Where has it gone?

      Leon

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top