---
title: "Crystal Report with DataSet"  
description: "A Crystal Report with DataSetIn order to create a crystal report with Dataset, first, we have to add a new Dataset (.xsd) file.  To add the dataset"  
author: "Chris Anderson"  
published: 2011-08-24  
updated: 2020-07-05  
canonical: https://www.mindstick.com/articles/610/crystal-report-with-dataset  
category: "crystal report"  
tags: ["crystal report"]  
reading_time: 3 minutes  

---

# Crystal Report with DataSet

## A Crystal Report with DataSet

In order to create a [**crystal report**](https://www.mindstick.com/articles/613/group-name-field-in-crystal-report) with Dataset, first, we have to add a new Dataset (.xsd) file.\

To add the dataset file **Project->Add New Item.**

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/f977907a-bca2-4568-bb28-afe2574989f5.png)

Then select the Dataset file from the “New Item” template.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/15ee9280-ba39-46dc-91fb-203c9449ef74.png)

After adding a dataset, take a Datatable [from the toolbox](https://www.mindstick.com/Articles/321/timer-control-in-vb-dot-net) and add columns in DataTable as shown in the above figure.

You can add multiple columns as per your need, here I added four columns in DataTable i.e. Column1, Column2, Column3, Column4.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/9d222c72-bfac-4348-a148-544486856fa2.png)

The next window looks like the following and you have to select your created Dataset under “Project Data”, and click “Insert Table”, and then click OK.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/1b1d48a3-64db-4c1f-9621-78773181389e.png)

After inserting the Datatable set the columns of the Datatable in the details section of the crystal report.

You can also customize the report by using the toolbox (Ctrl+Alt+x) of the crystal report.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/8407355e-4330-4b6d-b6fb-4a74a132df82.png)

Drag the Crystal Report Viewer from the toolbox and drop it into your application form.

Here I had also selected a button (Show Details) in order to show the report on the click of a button.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/9a5ff9c1-22d9-4067-b798-3b43f328d650.png)

If we create or upgrade the crystal report in an application of [**Visual Studio 2010**](https://www.mindstick.com/articles/1363/crud-operation-c-sharp-using-stored-procedure-web-service-windows-service-and-crystal-report), then we also have to specify

the following piece of code in **Application Configuration File (app.config)**

```
<configuration>       <startupuseLegacyV2RuntimeActivationPolicy="true">              <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>       </startup></configuration>
```

We also have to use the namespace i.e. CrystalDecisions. [**CrystalReports**](https://www.mindstick.com/articles/930/crystal-report-in-visual-studio-2010). The engine in order to create a report dynamically with the dataset.

```
using CrystalDecisions.CrystalReports.Engine;
```

From the code mentioned below, we can access the designation table details from

the database and fill that table into DataSet and set the data source of the crystal report viewer.

```
private void button1_Click(object sender, EventArgs e){
   SqlConnection cnn;   string connectionString = null;   string sql = null;   connectionString = "data source=server name; initial catalog=database name;user                        id=your id; password=your password";   cnn = new SqlConnection(connectionString);   cnn.Open();   sql = "select employee_id as Column1,employee_name as Column2,employee_designation as
         Column3,employee_city as Column4 from designation";   SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);   cnn.Close();   DataSet1 ds = new DataSet1();   dscmd.Fill(ds, "DataTable1");   CrystalReport1 objRpt = new CrystalReport1();   objRpt.SetDataSource(ds.Tables[0]);   crystalReportViewer1.ReportSource = objRpt;   crystalReportViewer1.Refresh();
 }
```

Now we can see the output of our report by running an application.

![Crystal Report with DataSet](https://www.mindstick.com/mindstickarticle/b1fa8372-12c0-4b0e-a870-138fe135a095/images/ad4ce99f-8f3e-4e89-a2ae-7c2ee66647e3.png)

---

Original Source: https://www.mindstick.com/articles/610/crystal-report-with-dataset

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
