SIGN UP MEMBER LOGIN:    
ARTICLE

Build Reports using Crystal Reports and Stored Procedures

Posted by Vilas Gite Articles | Crystal Reports C# May 03, 2011
In this article, you will see how to get data using a stored procedure and build reports in Visual Studio and Crystal Reports.
Reader Level:
 


Introduction

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.


CrystalReports1.gif


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

CrystalReports2.gif

Data of Store Procedure has been bind to DataGridView and fill by Query.

CrystalReports3.gif

There is Store Procedure spSALES created in database.

CrystalReports4.gif
 
Crystal Report format and connection with table.

CrystalReports5.gif

Code on Preview button.

private void btnPrev_Click(object sender, EventArgs e)
      {
            Form frmINVP = new INV_PRINT();
            frmINVP.ShowDialog();
      }

CrystalReports6.gif

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

CrystalReports7.gif

Now, Crystal Reports works easily within Visual Studio.
Thanks!

Further Readings

Crystal Reports section has many more articles on Crystal Reports development.

Login to add your contents and source code to this article
share this article :
post comment
 

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. :(

Posted by Brinda Pushpa Nov 30, 2011

Nice Article.

Posted by sumanth d Nov 24, 2011

I need this project database also...

Posted by mohan kumar Nov 16, 2011

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..

Posted by mohan kumar Nov 16, 2011

Hi, Is It possible to remove zero field value from crystal Report. if yes then how can i remove

Posted by anish sahu Oct 31, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor