Stored Procedures are used to improve the performance of an application when getting data from a database. In this article, a stored procedure is used to get data from the database. The procedure also has two date parameters that are used to specify a date range, from and to.
Crystal Reports in Visual Studio
Crystal Reports is a great business objects tool available in Visual Studio to build reports. Crystal Reports is used for building simple to complex reports including daily reports as sales reports, delivery challans, and stock reports.
Get Started
Let's get started.
Create a new Windows application in Visual Studio and add a new item - Crystal Reports to the Form.
You can right click on the project name in Solution Explorer and select Add New Item and select Crystal Reports from the available items.
The complete code is given below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SALE_INVENTORY
{
public partial class frmSALES : Form
{
public frmSALES()
{
InitializeComponent();
}
private void frmSALES_Load(object sender, EventArgs e)
{
}
private void fillToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.spSALESTableAdapter.Fill(this.sP_SALESDATA.spSALES, new System.Nullable<System.DateTime>(((System.DateTime)(System.Convert.ChangeType(startdateToolStripTextBox.Text, typeof(System.DateTime))))), new System.Nullable<System.DateTime>(((System.DateTime)(System.Convert.ChangeType(enddateToolStripTextBox.Text, typeof(System.DateTime))))));
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
Data of Store Procedure has been bind to DataGridView and fill by Query. 
There is Store Procedure spSALES created in database. 
Crystal Report format and connection with table.
Code on Preview button.
private void btnPrev_Click(object sender, EventArgs e)
{
Form frmINVP = new INV_PRINT();
frmINVP.ShowDialog();
} 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace SALE_INVENTORY
{
public partial class INV_PRINT : Form
{
public INV_PRINT()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnPrev_Click(object sender, EventArgs e)
{
ReportDocument cryRPT = new ReportDocument();
cryRPT.Load("C:\\INV.rpt");
crv1.ReportSource = cryRPT;
crv1.Refresh();
}
}
}
Now, Crystal Reports works easily within Visual Studio.
Thanks!
Further Readings
Crystal Reports section has many more articles on Crystal Reports development.

SubashPosted Jul 29, 2016, 7:50 AM
Thank you very much i hope this will very Helpful to me
Gowtham RajamanickamPosted Mar 27, 2015, 2:42 PM
good
MaePosted Sep 9, 2012, 2:34 AM
Please help me:( The result of the survey system wont appear in the crystal report. Please and thank you! DateTime pdateFrom = (DateTime)Convert.ToDateTime(Session["dFrom"].ToString()); DateTime pdateTo = (DateTime)Convert.ToDateTime(Session["dUntil"].ToString()); SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(strConn); try { SqlCommand cmd = new SqlCommand(sp, sqlConn); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_GetSurvAns"; cmd.Parameters.AddWithValue("@fromdate", pdateFrom); cmd.Parameters.AddWithValue("@todate", pdateTo); sqlQuery = "SELECT * from survAns,quesTable"; sqlConn.Open(); SqlDataAdapter Da = new System.Data.SqlClient.SqlDataAdapter(sqlQuery, sqlConn); Ds = new DataSet(); Da.Fill(Ds, "usp_GetSurvAns"); Dt = Ds.Tables["usp_GetSurvAns"]; SqlDataReader dr = cmd.ExecuteReader(); dr.Close(); if (Dt.Rows.Count > 0) { crviewer.ReportSource = null; crByDate.SetDataSource(Dt); crByDate.SetParameterValue("dtFrom", pdateFrom); crByDate.SetParameterValue("dtTo", pdateTo); crviewer.ReportSource = crByDate; } } finally { sqlConn.Close(); } }
Vilas GitePosted Aug 21, 2012, 7:06 AM
Brinda pls provide your code
Vilas GitePosted Aug 21, 2012, 7:06 AM
Brinda pls provide your code
Brinda VishalakshiPosted Nov 30, 2011, 2:41 AM
I m working VS2008 and C#3.5 , I'm New to crystal report. i wnt to display details in crystal report based on Billno from DB. one bill no have more than one rows . so how can i view the details based bill no. One bill no details in one page . plz help me for this prob. :(
sumanth deditedPosted Nov 24, 2011, 6:27 AMEdited Nov 24, 2011, 6:28 AM
Nice Article.
mohan kumarPosted Nov 16, 2011, 2:47 AM
I need this project database also...
mohan kumarPosted Nov 16, 2011, 2:46 AM
Hay Vilas Gite..Can u give me this full project in which u have implemented "Build Reports using Crystal Reports and Stored Procedures"?? I need the full project source code..
anish sahuPosted Oct 31, 2011, 4:22 AM
Hi, Is It possible to remove zero field value from crystal Report. if yes then how can i remove
Jaypee HudaPosted Sep 10, 2011, 7:00 AM
Great!!!!!!! this is a good one.. You may check out the following links................. http://www.mindstick.com/Articles/3407277b-bcc9-4cdf-86ca-e21cd7fbee88/?Introduction%20of%20Crystal%20Report%20in%20C#.Net http://www.mindstick.com/Articles/f9b4064b-a57b-4024-a963-eb022fbf6118/?Crystal%20Report%20using%20Wizard
Iulia DuciucPosted Jun 8, 2011, 12:46 PM
Hello, I'm student at Computer science field...and this is my last year.I need some help with Crystal Report in C#.I have to finish my final project and I need help.Can somebody help me ? ( I need something like this :when I select a year from a combobox I have to generate from mysql database reports)
Randima egodawattaPosted May 22, 2011, 11:51 PM
Very good post.
Pablo PaauPosted May 4, 2011, 9:43 AM
I like this article because i new in .net languaje c# only one question. where is it the version the crystal report? thank no i find
Ankit NandekarPosted May 4, 2011, 2:54 AM
nice article