Home > DeveloperSection > Articles > CrystalReportViewer Control in C#.Net

CrystalReportViewer Control in C#.Net

Reporting Reporting 
0 Comment(s)
 24428  View(s)
Rate this:

CrystalReportViewer Control in C#.Net

Crystal Report is a Reporting Application that can generate reports from various Data Sources.

How to use CrystalReportViewer Control

Drag and drop CrystalReportViewer control from toolbox on the window Form.

CrystalReportViewer Control in C#.Net

Steps to create Crystal Report in C#.Net


·         Create a Dataset and define the schema by drag and drop the database table from Server Explorer.

·         Right Click Solution Explorer -> Add -> Add New Item -> choose DataSet.

·         Add new Connection 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.


·         Create Crystal Report.

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

Configure the Crystal Report.


·         Select Report Layout, ProjectData, ADO.NET Datasets

·         Expand ADO.NET Datasets and select the table

·         Select the fields


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()




  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


            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();


        //Create Crystal report document

            ReportDocument rptdc = new ReportDocument();

     //Set crystal report path


           //Bind dataset to reportdoucument


           //Bind ReportSource to crystalReportViewer

           crystalReportViewer1.ReportSource = rptdc;




Run the project

Data will bind in the CrystalReportViewer when application run.

CrystalReportViewer Control in C#.Net

Don't want to miss updates? Please click the below button!

Follow MindStick