Crystal Report in web application using c#

Reports in Web Application

                There are Only three thing we kept in your mind when we are creating a Reports in web application.

1.       XML Schema

2.       Cystal Report

3.       A “aspx” normal page where we call our Crystal Report

 

First we Create XML Schema.

                Add new Item in your Project and select XML Schema file is there in add Template.

Give a proper name and ok.

The code is given below according to my Code so please use it as reference not copy and paste

<?xml version="1.0" encoding="utf-8"?>

<xs:schema id="ApplicationDetails" targetNamespace="http://tempuri.org/ApplicationDetails.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/ApplicationDetails.xsd" xmlns:mstns="http://tempuri.org/ApplicationDetails.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" >

  <!--from here you start your code-->

  <xs:element name="ApplicationDetails"><!--This is Your table name. in your DataBase -->

    <xs:complexType>

      <xs:sequence>

        <!--Here is your Fields(Column) name..-->

        <xs:element name="AppID" type="xs:int" />

        <xs:element name="Name" type="xs:string" />

        <xs:element name="EmailAddress" type="xs:string" />

        <xs:element name="Address" type="xs:string" />

        <xs:element name="ContactNumber" type="xs:string" />

        <xs:element name="OFilename" type="xs:string" />

        <xs:element name="Skills" type="xs:string" />

       </xs:sequence>

    </xs:complexType>

  </xs:element>

</xs:schema>

 

In this code my .xsd file and my table name is same so may be you confuse but don't worry you read comment which is given alone with code. Now we have our .xsd file(XML Schema).

 

 

Now we move to our 2nd Step.

Again Open add new item Box for adding Crystal report.

See categories you find one reporting tag select that and  select Crystal Report in tamplate section click add

Vs2005/2008/2010 automatic open one dialoged box

 

No need to do any thing just press ok

 After press ok by you system will open one more Dialog box


Select “Create New Connection” according to image, after that select “ADO.NET” Click on

Plus Symbol

In this image select a path of your XML Schema which you create in  Step 1. And click finish.

If you get error remove all Comment in Your XML Schema.

Select ApplicationDetails and Click on   this button and click next

Select ApplicationDetails and Click on  button and click to finish

After click finish you will see page created with all your selected field

Step 3rd calling and loading

Call any page and put below code in Page_load event

// Here you witre database connectivity code and fatch data based on your

// requirment store data in DataTable object Dt

// Remember your database Query return only those filed which you add in Your // .xsd file(XML Schema)

 

if (dt.Rows.Count > 0)

{

                ApplicationReport.DisplayGroupTree = false;

                ApplicationReport.HasCrystalLogo = false;

                CrystalDecisions.CrystalReports.Engine.ReportDocument MyReportDocumenet = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                MyReportDocumenet.Load(Server.MapPath("~/Reports/ApplicationDetails.rpt"));

                MyReportDocumenet.SetDataSource(dt);

                ApplicationReport.ReportSource = MyReportDocumenet;

                ApplicationReport.DataBind();

            }