---
title: "CrystalReportViewer Control in C#.Net"  
description: "The CrystalReportViewer Control in C#.NetThe Crystal Report is a Reporting Application that can generate reports from various Data Sources.  How to"  
author: "Pushpendra Singh"  
published: 2011-01-24  
updated: 2020-08-17  
canonical: https://www.mindstick.com/articles/421/crystalreportviewer-control-in-c-sharp-dot-net  
category: "reporting"  
tags: ["reporting"]  
reading_time: 2 minutes  

---

# CrystalReportViewer Control in C#.Net

## The CrystalReportViewer Control in C#.Net

The [Crystal Report](https://www.mindstick.com/articles/930/crystal-report-in-visual-studio-2010) is a [Reporting](https://www.mindstick.com/articles/12967/portable-reporting-systems-and-mobile-device-management) [Application](https://www.mindstick.com/articles/12824/calculator-application-in-android) that can generate reports from various Data Sources.\

## How to use CrystalReportViewer Control

[Drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) CrystalReportViewer control from the [toolbox on the](https://www.mindstick.com/Articles/324/the-tooltip-control-in-vb-dot-net) [window Form](https://www.mindstick.com/forum/527/how-to-pass-datagridview-s-cells-value-to-another-window-form).

![CrystalReportViewer Control in C#.Net](https://www.mindstick.com/mindstickarticle/1130cd0a-731e-4813-8d6c-6deb7e6e304c/images/c7e17d21-53c9-4baa-83a5-ca119dfcf1ed.png)

**Steps to create Crystal [Report in C#](https://answers.mindstick.com/qa/30939/how-can-i-create-report-using-crystal-report-in-c-sharp-dapper-application).Net**

## Step1:

- Create a Dataset and define the schema by drag and drop the [database table](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table) from Server [Explorer](https://yourviews.mindstick.com/view/81617/now-it-is-time-to-say-goodbye-to-internet-explorer).
- Right Click Solution Explorer -> Add -> Add New Item -> choose DataSet.
- Add new [Connection](https://yourviews.mindstick.com/view/83497/a-40-year-old-man-has-been-arrested-in-connection-with-the-abe-shooting) in the Server Explorer and expand the connection to retrieve the database tables and choose the required table and drag and drop it in the Dataset xsd pane.

## Step2:

- Create Crystal Report.
- Right Click Solution Explorer -> Add -> Add New Item -> choose Crystal Report.

**Configure the Crystal Report.**

## STEPS:

- Select Report Layout, ProjectData, ADO.NET Datasets
- Expand ADO.NET Datasets and select the table
- Select the fields

## Code:

Open the Code window of the WebForm and write the following code.

```
using System;using System.Data;using System.Data.SqlClient;using System.Text;using CrystalDecisions.CrystalReports.Engine;using System.Windows.Forms; namespace WindowsFormsApplication1{     public partial class frmCrystalReportViewer : Form    {         public frmCrystalReportViewer()         {            InitializeComponent();         }  private void frmCrystalReportViewer_Load(object sender, EventArgs e)         {                   //Connect to the Database     string constring = "Server=(local);Database=my;User Id=sa;Password=sa";            SqlConnection sqlcon = new SqlConnection(constring);            //Open the connection            sqlcon.Open();            SqlCommand cmd = new SqlCommand();            SqlDataAdapter da = new SqlDataAdapter();            //Write the query            cmd.CommandText = "select * from regform";            da.SelectCommand = cmd;            cmd.Connection = sqlcon;            da.SelectCommand = cmd;            //create a dataset            DataSet ds = new DataSet();            da.Fill(ds);         //Create Crystal report document            ReportDocument rptdc = new ReportDocument();      //Set crystal report path    rptdc.Load("C:\\User\\WindowsFormsApplication1\\CrystalReport1.rpt");           //Bind dataset to reportdoucument            rptdc.SetDataSource(ds);           //Bind ReportSource to crystalReportViewer           crystalReportViewer1.ReportSource = rptdc;         }    }}
```

## Run the project

Data will bind in the CrystalReportViewer when the application run.

![CrystalReportViewer Control in C#.Net](https://www.mindstick.com/mindstickarticle/1130cd0a-731e-4813-8d6c-6deb7e6e304c/images/07c1b9da-f6e2-4635-b209-2e4b13da8996.png)

---

Original Source: https://www.mindstick.com/articles/421/crystalreportviewer-control-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
