Category Archives: Crystal Report

How to Export Crystal Report to PDF in ASP.Net using C#

How to Export Crystal Report to PDF format in asp.net.

We have already learned in older post how to create and bind crystal reports in asp.net.

Create and bind crystal reports in asp.net

Design a asp.net web form with crystalreportviewer along with a Button.

Export Crystal Reports to PDF format in asp.net

Export Crystal Reports to PDF format in asp.net

 

write below code on Button for export crystal reports to PDF in asp.net.

protected void Button1_Click(object sender, EventArgs e)
{
DataSet1.STUDENT_SELECTDataTable StuDT = new DataSet1.STUDENT_SELECTDataTable();
DataSet1TableAdapters.STUDENT_SELECTTableAdapter StuAdapter = new DataSet1TableAdapters.STUDENT_SELECTTableAdapter();

StuDT = StuAdapter.Select();
ReportDocument rept = new ReportDocument();

rept.Load(Server.MapPath(“~/CrystalReport.rpt”));
rept.SetDataSource((DataTable)StuDT);
CrystalReportViewer1.ReportSource = rept;

rept.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @”E:\Meera.pdf”);
}

 

Export Crystal Reports to PDF format in asp.net

Export Crystal Reports to PDF format in asp.net

Bind Crystal Reports without Database in ASP.Net using C#

Here, we will learn how to create and bind crystal reports in asp.net without use of any database. we generally use database for bind data to crystal reports, but in this example i will show you how to bind dynamically data to crystal reports at runtime. we will use here dataset method for bind data to crystal reports in asp.net.

First create asp.net web application and right click on Project >> Add New Item >> DataSet

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

– Add new Dataset to asp.net web application for bind dynamically crystal reports.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– Add New DataTable here for make dynamically columns for data. Add new DataTable in DataSet.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– After adding new DataTable add some columns which you want to bind in crystal reports. add some columns shows like below screen.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– do same process for add new columns in DataTable.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– Here, we took three columns ID, Name, City in this asp.net example.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– After creating DataTable in Dataset, now create new crystal reports for display data in asp.net.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– go to Field Explorer >> Database Field >> Database Expert >> Project Data >> ADO.Net DataSets

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

– Design the Crystal Reports with columns from Database Filed. drag some columns in crystal reports details section for display crystal reports in asp.net.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

now, add new crystalreportviewer on asp.net web forms for display crystal reports.

write below code for bind data to crystal reports in asp.net.

C# Code

    protected void Page_Load(object sender, EventArgs e)
{
DataSet1 ds = new DataSet1();
DataTable tbll = ds.Tables.Add(“Items”);
tbll.Columns.Add(“id”, Type.GetType(“System.Int32”));
tbll.Columns.Add(“Name”, Type.GetType(“System.String”));

tbll.Columns.Add(“City”, Type.GetType(“System.String”));

DataRow rowss;
int i = 1;
for (i = 1; i <= 9; i++)
{
rowss = tbll.NewRow();
rowss[“id”] = i;
rowss[“Name”] = “Name” + i;
rowss[“City”] = “City” + i;
tbll.Rows.Add(rowss);
}

ReportDocument rept = new ReportDocument();

rept.Load(Server.MapPath(“~/CrystalReport2.rpt”));
rept.SetDataSource((DataTable)ds.Tables[1]);
CrystalReportViewer1.ReportSource = rept;

}

VB.Net Code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim ds As DataSet1 = New DataSet1()
Dim tbll As DataTable = ds.Tables.Add(“Items”)
tbll.Columns.Add(“id”, Type.GetType(“System.Int32”))
tbll.Columns.Add(“Name”, Type.GetType(“System.String”))
tbll.Columns.Add(“City”, Type.GetType(“System.String”))

Dim rowss As DataRow
Dim i As Integer = 1
For i = 1 To 9 Step i + 1
rowss = tbll.NewRow()
rowss(“id”) = i
rowss(“Name”) = “Name” + i.ToString()
rowss(“City”) = “City” + i.ToString()
tbll.Rows.Add(rowss)
Next

Dim rept As ReportDocument = New ReportDocument()
rept.Load(Server.MapPath(“~/CrystalReport2.rpt”))
rept.SetDataSource(CType(ds.Tables(1), DataTable))
CrystalReportViewer1.ReportSource = rept

End Sub

– Here is the out put of dynamically bind data to crystal reports in asp.net using c#.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports in ASP.Net without Dataset.

Here, we learn how to create crystal reports in asp.net, and how to bind data to crystal reports from sql server database.  here we are bind data to crystal reports in ASP.Net without use of Dataset.

For binding data to crystal reports, first we must need to create a new database in sql server and create a table in database. Here we need not to create stored procedure for binding crystal reports.

Here, first we create new Database in sql server and create new Table within a Database.

– Create a new Table “DEMO” in SQL – server with some columns.

Create New Table in SQL-Server Database

Create New Table in SQL-Server Database

Here, We have created new Table UserMSt with Column Name and City.

Create New Table in SQL-Server Database

Create New Table in SQL-Server Database

Now , after create new database and table in sql server, now create a new asp.net web application for bind crystal reports.

Create New ASP.Net web application with C#

Create New ASP.Net web application with C#

– Add CrystalReportViewer on asp.net web forms from Toolbox for Display crystal reports.

Add CrystalReportViewer in asp.net webfom

Add CrystalReportViewer in asp.net webfom

Now, Right click on Project Title and go to Add New Item and select Crystal Report for add new Crystal Report in asp.net. here we can change the crystal reports name as our need.

Add New Crystal Report in ASP.Net

Add New Crystal Report in ASP.Net

When we Add new crystal reports, we have three options here select As a Blank Report and click OK.

Select As a Blank Report Property in Crystal Reports in ASP.Net

Select As a Blank Report Property in Crystal Reports in ASP.Net

Now, here we have created crystal reports now for binding data to crystal reports we have to do some step.

Field Explorer >> Database Field >> Database Expert >> Create New Connection >> OLE DB (ADO)

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

In database Expert select OLE DB (ADO) option in Create New Connection option then click OK Button to go next step.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

Here, we have list of Database Server Provider for choose our appropriate database provide.

Select Microsoft OLE DB Provider for SQL Server click next to go ahead.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

Fist check (tick) the Integrated Security  option check box and then write the your Sql Server name like ComputerName/ServerName.

Here we have write .\NEWSQLEXPRESS indicate the sql server name. if we write right sql server name then all the Database of this server will be automatically displayed in below Database Dropdownlist.

Select your Database which you want to display in crystal reports and click next button to go ahead.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

here, we do nothing, just click finish button to finish the sql server connection process.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

Now, We have already connect the DEMO Database in our asp.net web application crystal reports Database Expert field.
Here, we can see all the table of DEMO Database, just add the table for display crystal reports by clicking arrow button.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

We can see here UserMst Table already added for bind crystal reports.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

now, just design the crystal reports with name and city columns like below screen.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

we can see the crystal reports preview without run the asp.net web application, just click the Main Reports Preview button.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

Here, is the final crystal reports out put of asp.net web application.

Create and Bind Crystal Reports in ASP.Net using C#

Create and Bind Crystal Reports in ASP.Net using C#

Alternate Row color in Crystal Reports in ASP.Net

Here, we basically design the crystal reports to set the alternate row color in asp.net.

For design crystal reports first create crystal reports and bind data to it, we have already learned in previous post.

Create and Bind Crystal Reports in ASP.Net C#

Open the Crystal Reports >> Details >> Selection Expert >> Color

First, Right click on the Details and choose Selection Experts property and click the color Tab.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

Check the Background Color option checkbox and choose color in color Tab.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

After select background color go to the Format Formula Editor.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

if RecordNumber mod 2 = 0 then crSilver else crNoColor.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

Save and exit formula color editor.

Now run the crystal reports and you can see the alternate row color silver and white in the details section of crystal reports.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

 

if RecordNumber mod 2 = 0 then crSilver else crGreen.

Save and exit formula color editor.

Now run the crystal reports and you can see the alternate row color silver and Green in the details section of crystal reports.

Alternate Row color in Crystal Reports in ASP.Net

Alternate Row color in Crystal Reports in ASP.Net

Paging in Crystal Reports in ASP.Net with C# and VB.Net

In older post we have already leaned how to create and bind data in crystal report from database in asp.net we application.

Now, today we will lean how to make paging in crystal reports in asp.net using c# and vb language.

For doing paging in crystal reports first we have to create and bind data to crystal reports in asp.net.

Check link for create and bind Crystal Reports

After Creating and Binding data to crystal reports, we can do the paging in crystal reports.

For paging  Details >> Selection Expert >> New Page Before

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

For Implement paging in crystal reports right click on details section and select Selection Expert Property.
Check the New Page Before option on selection Expert property of Details section and edit the new page before property.

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net.

– Write and save formula in New Page Before property for paging in crystal reports in asp.net.

IF Remainder (RecordNumber, 10) = 0 THEN
TRUE
ELSE
FALSE

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

– Write below code at Page_PreInit Event for bind the crystal reports in asp.net web forms.

C# Code
Import namespace  : using CrystalDecisions.CrystalReports.Engine;

 protected void Page_PreInit(object sender, EventArgs e)
{
DataSet1.STUDENT_SELECTDataTable StuDT = new DataSet1.STUDENT_SELECTDataTable();
DataSet1TableAdapters.STUDENT_SELECTTableAdapter StuAdapter = new DataSet1TableAdapters.STUDENT_SELECTTableAdapter();

StuDT = StuAdapter.Select();
ReportDocument rept = new ReportDocument();

rept.Load(Server.MapPath(“~/CrystalReport.rpt”));
rept.SetDataSource((DataTable)StuDT);
CrystalReportViewer1.ReportSource = rept;
}

VB.Net Code
Import namespace  : Imports CrystalDecisions.CrystalReports.Engine

Dim StuDT As DataSet1.STUDENT_SELECTDataTable = New DataSet1.STUDENT_SELECTDataTable()
Dim StuAdapter As DataSet1TableAdapters.STUDENT_SELECTTableAdapter = New DataSet1TableAdapters.STUDENT_SELECTTableAdapter()

StuDT = StuAdapter.Select()
Dim rept As ReportDocument = New ReportDocument()

rept.Load(Server.MapPath(“~/CrystalReport.rpt”))
rept.SetDataSource(CType(StuDT, DataTable))
CrystalReportViewer1.ReportSource = rept

– Here is a out put of paging in crystal reports in asp.net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

 

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Implement Paging in Crystal Report in ASP.Net with C# and VB.Net

Create and Bind Crystal Report in ASP.Net C# using Dataset

Here, we learn how to create crystal reports in asp.net, and how to bind data to crystal reports from sql server database.  here we are using dataset method for bind data to crystal reports in ASP.Net.

For binding data to crystal reports, first we must need to create a new database in sql server and create a table and a select stored procedure in database. after finishing this we have to make connection between asp.net web application and sql server using Dataset method.

Here, first we create new Database in sql server and create new Table within a Database.

– Create a new Table “StuMSt” in SQL – server with some columns.

 

Create a new Table in sql server for Bind Crystal Report.

Create a new Table in sql server for Bind Crystal Report.

– Create a SELECT Stored Procedure in sql server for select data.

Create a new Select Stored Procedure in sql server for Bind Crystal Report.

Create a new SELECT Stored Procedure in sql server for Bind Crystal Report.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[STUDENT_SELECT]
AS
BEGIN

SELECT * FROM STUMST

END

 

Now, create a new asp.net web application for bind crystal report.

Create New ASP.Net web application with C#

Create New ASP.Net web application with C#

 

After, create a asp.net web application we have to make connection between asp.net web application and sql server database. we are using dataset method for asp.net connection.

Create New DataSet in asp.net web application in Solution Explorer.

Solution Explorer >> Right Click on Project >> Add New Item >> DataSet

Create New Dataset in ASP.net for sql server connectivity.

Create New Dataset in ASP.net for sql server connectivity.

 

Create New Dataset in ASP.net for sql server connectivity.

Create New Dataset in ASP.net for sql server connectivity.

 

Create New Dataset in ASP.net for sql server connectivity.

Create New Connection with SQL Express for connectivity.

 

Create New Dataset in ASP.net for sql server connectivity.

Bind sql stored procedure with dataset.

Create New Dataset in ASP.net for sql server connectivity.

Bind Select Stored procedure to dataset in asp.net

 

Create New Dataset in ASP.net for sql server connectivity.

Create New Dataset in ASP.net for sql server connectivity.

 

Create New Dataset in ASP.net for sql server connectivity.

Create New Dataset in ASP.net for sql server connectivity.

 

Now, finishing dataset binding we create a new crystal reports. for Display crystal reports on web form we have to take a CrystalReportViewer  from toolbox on web asp.net web form.

Add CrystalReportViewer on asp.net web forms for display Crystal Report.

Add CrystalReportViewer on asp.net web forms for display Crystal Report.

 

Now, Create a New Crystal Reports in asp.net web application.

Solution Explorer >> Right Click on Project >> Add New Item >> CrystalReport

Add New Crystal Report in asp.net web application.

Add New Crystal Report in asp.net web application.

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

– There are main five section in Crystal Reports.
1. Report Header : Report Header Generally used to Display Heading/Title of the Reports.
2. Page Header : Page Header used to Display Content/Data Heading or Title.
3. Detail : Detail used to Display the Data/Content of your Reports.
4. Report Footer : Report Footer used to Display Footer of the Reports.
5. Page Footer : Page Footer used to Display Page Number of the Reports.

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet

– here is code for bind crystal report.

C# Code
– first add name space : using CrystalDecisions.CrystalReports.Engine;

 protected void Page_Load(object sender, EventArgs e)
{
DataSet1.STUDENT_SELECTDataTable StuDT = new DataSet1.STUDENT_SELECTDataTable();
DataSet1TableAdapters.STUDENT_SELECTTableAdapter StuAdapter = new DataSet1TableAdapters.STUDENT_SELECTTableAdapter();

StuDT = StuAdapter.Select();

ReportDocument rept = new ReportDocument();
string spath = “E:/BLOG/RExample/CrystalReport.rpt”;
rept.Load(spath);
rept.SetDataSource((DataTable)StuDT);
CrystalReportViewer1.ReportSource = rept;

}

VB.Net Code
Import namespace  : Imports CrystalDecisions.CrystalReports.Engine

Dim StuDT As DataSet1.STUDENT_SELECTDataTable = New DataSet1.STUDENT_SELECTDataTable()
Dim StuAdapter As DataSet1TableAdapters.STUDENT_SELECTTableAdapter = New DataSet1TableAdapters.STUDENT_SELECTTableAdapter()

StuDT = StuAdapter.Select()
Dim rept As ReportDocument = New ReportDocument()

rept.Load(Server.MapPath(“~/CrystalReport.rpt”))
rept.SetDataSource(CType(StuDT, DataTable))
CrystalReportViewer1.ReportSource = rept

 

Create and Bind Crystal Report in ASP.net using DataSet

Create and Bind Crystal Report in ASP.net using DataSet