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


  How to print Crystal Reports in C#

The following program shows how to print multiple copies of Crystal reports from C#.

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 following program generate a Crystal Reports from product table and print 2 copies of report without using CrystalReportViewer in C#. The program generate report from Product table , the step by step tutorial for creating a Crystal Reports from C# section explains how to create report from Product table. Also the program dynamically passing the logon parameters to Crystal Report. If you don't know how to pass dynamic logon parameter please take a look at the section C# Dynamic logon parameters in Crystal Reports.

Hope you understand the previous section well. Create a Crystal report from Product Table and copy and paste the following source code in the project.

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

         C# Source Code Download           Print Source Code
         How to print Crystal Reports in C# - Download
        
C# Tutorial

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

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

            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;

            crConnectionInfo.ServerName = "YOUR SERVERNAME";
            crConnectionInfo.DatabaseName = "DATABASE NAME";
            crConnectionInfo.UserID = "USERID";
            crConnectionInfo.Password = "PASSWORD";

            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            cryRpt.Refresh();
            cryRpt.PrintToPrinter(2, true, 1, 2);

        }
   }
}

cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
The Crystal Reports file path in your 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

  crConnectionInfo.ServerName = "YOUR SERVERNAME";

crConnectionInfo.DatabaseName = "DATABASE NAME";
crConnectionInfo.UserID = "USERID";
crConnectionInfo.Password = "PASSWORD";


You have to pass the necessary database connection information.

Now you can run the program . When you run this program the program will print multiple copies of Crystal Reports.


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 Formula Field
*     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 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.