Introduction
This article provides a sample of a Windows application for student result details having a different subject in Visual Studio 2010. We also generate a Crystal Reports report in this application. We have a database table with Student Result Details. We also provide a search facility to find specific student results.
Note
We require Crystal Reports for Visual Studio 2010. To download Crystal Reports for Visual Studio 2010, exe or Zip, or for more information, click Here.
Step 1
Now we create a new project in Visual Studio 2010 using C#. From the file menu select "New Project". Here we use "Prg25_Stud_Crystal_Demo".
We add all the required controls to a Windows Forms form. We use Textboxes, Lables and Buttons.
We also add the Crystal Report Viewer for displaying the report of Student Results.
Step 2
We add Crystal Reports to the application. For that go to Solution Explorer and click on "Add New Item" then add "Crystal Reports" from the given installed Templates or Items.
"Solution Explorer" ->"Add" -> "New Item" (Ctrl+Shift+A) -> "Crystal Reports".
Step 3
After creating Crystal Reports we require a "Dataset" for Crystal Reports to display the student data in the report. For that go to the Solution Explorer and click on "Add New Item" then add a "DataSet" from the given installed Templates or Items.
"Solution Explorer" ->"Add" -> "New Item" (Ctrl+Shift+A) -> "DataSet".
To configure the Dataset we drag and drop the database in the DataSet configure wizard.
After configuring the DataSet we must apply those datasets to Crystal Reports. This we do at runtime using C# code. We add database fields to the Crystal Report. We also generate Dynamic Fields (formula fields) to the Crystal Report, such as Per and Total.
Step 4
After completing the design we need to do the coding. We add code in the Different Button Event to perform the Different task. Like for the "Submit" Button add the Student Records to the Database.
For searching purposes, on the "Search" Button we add code to find the specific Student Record.
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace PRG25_STUD_CRYSTAL_DEMO
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbStudent.mdf;Integrated Security=True;User Instance=True");
SqlCommand com;
SqlDataAdapter adp = new SqlDataAdapter();
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void btn_submit_Click(object sender, EventArgs e)
{
con.Open();
com = new SqlCommand("insert into tbl_student values ("+txt_rollno.Text+",'"+txt_name.Text+"','"+txt_sub1.Text+"','"+txt_sub2.Text+"','"+txt_sub3.Text+"')",con);
int x = com.ExecuteNonQuery();
con.Close();
if (x > 0)
{
ds.Tables[0].Rows.Clear();
CrystalAddData();
MessageBox.Show("Record Inserted");
}
}
private void Form1_Load(object sender, EventArgs e)
{
CrystalAddData();
}
public void CrystalAddData()
{
adp = new SqlDataAdapter("select * from tbl_student", con);
adp.Fill(ds);
ReportDocument rd = new ReportDocument();
rd.Load(@"~\CrystalReport1.rpt");
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
}
private void btn_search_Click(object sender, EventArgs e)
{
if (txt_search .Text == "")
{
MessageBox.Show("Enter Roll No");
}
else
{
ds.Tables[0].Rows.Clear();
adp = new SqlDataAdapter("select * from tbl_student where sno=" + txt_search .Text + "", con);
adp.Fill(ds);
ReportDocument rd = new ReportDocument();
rd.Load(@"~\CrystalReport1.rpt");
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
}
}
private void btn_all_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows.Clear();
CrystalAddData();
}
}
}
Output
Summary
Finally we have an application to generate student results and also generate the result Reports. We also export the report in a different format, like PDF, Word document and so on.
This application can help you to understand how to create a small application for reporting purposes.
I hope this article does help you.
Thank you.

Pranay PatelPosted Jun 26, 2016, 1:00 PM
Can you provide error log which help me to get more idea about error?
GokulPosted Jun 11, 2016, 1:58 AM
how can i clear this error
GokulPosted Jun 11, 2016, 1:57 AM
i am getting error for file can't be load
Pranay PatelPosted May 28, 2016, 7:32 AM
Before running this example need to install crystal report version for visual studio 2010.
Pradeep SahooPosted May 27, 2016, 7:57 PM
giving error report cannt be loaded ...need help ...Thanks for sharing
Ammar ShaukatPosted Oct 8, 2015, 12:50 AM
Is there any material on crystal reports using Entity Framework ?
narendra patelPosted Apr 26, 2015, 8:12 AM
i am getting this error :- the report has no tables
narendra patelPosted Apr 26, 2015, 8:06 AM
i am getting this error :- the report has no tables
sathish pPosted Mar 3, 2015, 11:54 PM
Good
satish GPosted Feb 27, 2015, 7:54 AM
getting exception "Load report failed" inner exception is {"Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack."} can u please reply me
soundara rajanPosted Nov 18, 2014, 4:55 AM
thanx bro...article is easily understood the concept...
Surendra MishraPosted May 10, 2014, 2:10 AM
i tried to run this window application ..i get an error of LOAD REPORT FAILED..please help me out..
archna bhayanaPosted May 7, 2014, 6:54 AM
hey, thank u for this article but when i tried to run this window application ..i get an error of LOAD REPORT FAILED..please help me out..
Saadi KhanPosted Jan 12, 2014, 2:07 AM
Hi, please visit the mentioned link to create a crystal report http://www.thesstech.com/content/how-create-crystal-report-visual-studio-2010