0% found this document useful (0 votes)
14 views10 pages

basic crystal report tutorial with example

This document provides a tutorial for creating a basic Crystal Report in a Windows Forms application using C# and VB.Net, specifically utilizing Microsoft's Northwind Database. It outlines the steps to add a Typed DataSet, configure a DataTable, and set up the Crystal Report and its viewer. The tutorial includes code snippets for populating the report with data and troubleshooting common errors related to Crystal Reports integration.

Uploaded by

Kibrom Embza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

basic crystal report tutorial with example

This document provides a tutorial for creating a basic Crystal Report in a Windows Forms application using C# and VB.Net, specifically utilizing Microsoft's Northwind Database. It outlines the steps to add a Typed DataSet, configure a DataTable, and set up the Crystal Report and its viewer. The tutorial includes code snippets for populating the report with data and troubleshooting common errors related to Crystal Reports integration.

Uploaded by

Kibrom Embza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

‫ﺣﺿﺭﺕ ﺧﻭﺍﺟہ ﺳﻳﺩﻧﺎ ﻣﻌﻳﻥ ﺍﻟﺩﻳﻥ ﺣﺳﻥ ﭼﺷﺗﯽ ﺳﻧﺟﺎﺭی ﺍﺟﻣﻳﺭی ﺭﺣﻣۃ ﷲ ﻋﻠﻳہ‬

Unveiling the Top 10 Enigmatic Creatures Rarely Witnessed by Humans


News Clicks24

Ex Send Email ASP.Net

Basic Crystal Report Tutorial with example in Windows Forms


(WinForms) Application using C# and VB.Net
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

In this article I will explain a tutorial with an example, to create a basic Crystal Report in Windows
Forms (WinForms) Application using C# and VB.Net.

The Crystal Report will be populated using Typed DataSet in Windows Forms (WinForms)
Application using C# and VB.Net.

Note: By default, Visual Studio 2010, 2012 and 2013 does not include Crystal Reports henc
e you need to download the Crystal Reports 13. Refer my following articles.
Download Crystal Reports for Visual Studio 2010, 2012, 2013, 2015 and 2017.

Database

Here I am making use of Microsoft’s Northwind Database. The download and install instructions
are provided in the following article.

Download and install Northwind Database

1. Add Typed DataSet to the project


This article makes use of Disconnected Architecture to connect Crystal Reports with Database
and hence Typed DataSets will be used.

2. Adding DataTable to the Typed DataSet


Our next step would be to add a DataTable to the Type DataSet.

2 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

3. Adding Columns or fields to DataTable

In the DataTable we need to specify the column names that we want to display in the Crystal
Report.

Note: The Column Names of the DataTable must exactly match with the actual Database T
able column names.

By default all the columns are of String Data Type but you can also change the data type as per
your need.

4. Add Crystal Report to the project


Now you will need to add a Crystal Report to the project. You can give it name as per your choice.

3 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

As soon as you click OK you get the following dialog. You must select Using the Report Wizard
option.

Once you press OK in the above dialog, the Report Wizard starts and you get the following dialog
where you need to choose the type of Database connection for your Crystal Report. Since we are
using DataSet we will choose the Customers DataSet.

4 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

Next the Wizard will ask for the Columns or Fields from the Customer DataSet you need to display
on the Crystal Reports. You can choose either all or specific fields as per you choice.

5 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

Note: There are more steps in the Wizards but those are Optional hence are not included in
this article.

Once you click Finish your Crystal Report should look as below.

5. Adding Crystal Report Viewer to the Form


In order to display the Report, we will need to add CrystalReportViewer control to the Form from

6 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

the Toolbox.

Note: If you are unable to see CrystalReportViewer in the Visual Studio ToolBox, please ref
er my article Crystal Report Viewer missing from ToolBox in Visual Studio 2010.

Once you add the CrystalReportViewer control to the Form, your Form must look as below.

6. Populating the Crystal Report from Database


Inside the Form Load event, first the Customers DataSet is populated with records from the
Customers Table.
The Customers DataSet is set as a DataSource for the Crystal Report.
Finally, the Crystal Report is set as ReportSource for the CrystalReportViewer control.
C#

Code

7 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

private void Form1_Load(object sender, EventArgs e)


{
CustomerReport crystalReport = new CustomerReport();
Customers dsCustomers = GetData();
crystalReport.SetDataSource(dsCustomers);
this.crystalReportViewer1.ReportSource = crystalReport;
this.crystalReportViewer1.RefreshReport();
}

private Customers GetData()


{
string constr = @"Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated
Security = true";
using (SqlConnection con = new SqlConnection(constr))
{

VB.Net

8 of 10 9/26/2023, 6:03 AM
Basic Crystal Report Tutorial with example in Windows Forms WinFo... https://www.aspsnippets.com/Articles/Basic-Crystal-Report-Tutorial-wi...

Dim dsCustomers As Customers = GetData()


crystalReport.SetDataSource(dsCustomers)
Me.crystalReportViewer1.ReportSource = crystalReport
Me.crystalReportViewer1.RefreshReport()
End Sub

Private Function GetData() As Customers


Dim constr As String = "Data Source=.\Sql2005;Initial Catalog=Northwind;Integ
rated Security = true"
Using As New SqlConnection(constr)

Screenshot

Note: If you get the following error while running the above application, please refer my arti

9 of 10 9/26/2023, 6:03 AM
cle Crystal Reports: Could not load file or assembly crdb_adoplus.dll.
Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal
Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x
86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file spe
cified. Company

Downloads

Download Code

Explore Follow us
Download Free Word/PDF/Excel API

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy