Home > DeveloperSection > Beginner > Crystal Report with DataSet

Crystal Report with DataSet


Crystal Report Crystal Report 
Ratings:
2 Comment(s)
 11604  View(s)
Rate this:

Crystal Report with DataSet

In order to create a crystal report with Dataset, first we have to add new Dataset (.xsd) file.

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

Crystal Report with DataSet

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

Crystal Report with DataSet

After adding a dataset, take a Datatable from toolbox 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

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

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

Drag the Crystal Report Viewer from 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 button.

Crystal Report with DataSet

If we create or upgrade the crystal report in an application of Visual Studio 2010, then we also have to specify 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.Engine in order to create a report dynamically with 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 crystalReportViewer.

 

 

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

 


nice article

By aken H on   5 years ago

nice article.

thanks.


Facing this error while creating report

By chetna balani on   2 years ago
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_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.

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

Follow MindStick