CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  C# Crystal Reports Formula Field

The following C# - Crystal Reports section describes how to add a formula field in the Crystal Reports .

All C# Crystal Reports Tutorial in this website is based on the following database - crystaldb. So before you begin this section , please take a look at the database structure of crystaldb - Click Here C# crystaldb

If you are new to Crystal Reports and do not know how to create Crystal Reports from C# , please take a look at the section step by step tutorial for creating a Crystal Reports from C#.

The situations when formula field is using :

If you have a Crystal Reports with Qty and Price fields and you need an additional field in your Crystal Reports for Total, that is TOTAL = QTY X PRICE . In these types of situations you can use the Formula Field in Crystal Reports.

In this C# Crystal Reports tutorial we are showing that all orders with qty and price and the total of each row , that means each in each row we are showing the total of qty and price.

Before starting this tutorial Create a new Crystal Reports with fields CustomerName , Order Date , Product Name and Product Price . If you do not know how to create this report , just look the previous tutorial C# Crystal Reports from multiple tables . In that report selecting only four fields , here we need one more field Product->Price and one formula field Total.

After you create the above Crystal Reports, your CR designer screen is look like the following picture :

csharp-crystal-formula-designer

Next step is to create a Formula Field for showing the result of Qty X Price .

Right Click the Formula Field in the Field Explorer and click New. Then you will get an Input Message Box , type Total in textbox and click Use Editor.

csharp-crystal-report-formula-editor

Now you can see the Formula Editor screen . Here you can enter which formula you want . Here we want the result of Qty X Price . For that we select OrderDetails.Qty , the multipy operator (*) and Product.Price . Double click each field for selection.

csharp-crystal-formula-editor

Now you can see Total Under the Formula Field . Drag the field in to the Crystal Reports where you want to display Total.

csharp-crystal-report-formula-designer

Now the designing part is over and the next step is to call the Crystal Reports in C# and view it in Crystal Reports Viewer control .

Select the default form (Form1.cs) you created in C# and drag a button and a CrystalReportViewer control to your form .

You have to include CrystalDecisions.CrystalReports.Engine in your C# Source Code.

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

Copy and paste the following source code and run your C# project

         C# Source Code Download           Print Source Code
         C# Crystal Reports Formula Field - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }
    }
}

cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
The Crystal Reports file path in your C# project files location, there you can see CrystalReport1.rpt . So give the full path name of Crystal Reports file like c:\projects\crystalreports\CrystalReport1.rpt

When you run this program you will get your screen like the following picture.

csharp-crystal-report-formula-final



C# Crystal Reports Related Contents
*     C# Crystal Reports sample databse
*     C# Crystal Reports step by step
*     C# Crystal Reports from multiple tables
*     C# Crystal Reports String parameter
*     C# Crystal Reports Integer parameter
*     C# Crystal Reports Date parameter
*     C# Crystal Reports Dynamic Logon parameters
*     C# Crystal Reports Summary Field
*     C# Crystal Reports Export to Pdf
*     C# Crystal Reports Export to Excel
*     Email Crystal Reports from C# Application
*     C# Crystal Reports without database
*     C# Crystal Reports from SQL Query
*     Dynamic Crystal Reports from C# Application
*     C# Crystal Reports from XML
*     C# Crystal Reports - sub reports
*     C# Crystal Reports - on demand sub reports
*     C# Crystal Reports - Date to Date
*     How to print Crystal Reports in C#
*     How to deploy Crystal Report
*     How to Crystal Report Merge Module
*     5 Tests for Top Performance by Jason Dove
*     3 New Uses For Sub Reports by Jason Dove


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.