Click here to Skip to main content
15,886,806 members
Articles / Web Development / ASP.NET

Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report

Rate me:
Please Sign up or sign in to vote.
4.85/5 (112 votes)
20 Jan 2011CPOL9 min read 704.1K   23.4K   209  
This article will help beginners to work with Crystal reports features easily.
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine

Partial Class TestCrystal
    Inherits System.Web.UI.Page

    Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click
        Dim rptDoc As New ReportDocument
        Dim ds As New dsTestCrystal
        'Dim sqlCon As SqlConnection
        Dim dt As New DataTable

        'dt.TableName = "Crystal Report Example"
        'sqlCon = New SqlConnection("server='servername';Initial Catalog='databasename';user id='userid';password='password'")
        'Dim da As New SqlDataAdapter("select Stud_Name, Class, Subject, Marks from stud_details", sqlCon)

        'da.Fill(dt)

        'dt.WriteXmlSchema(Server.MapPath("database.xsd"))
        'dt.WriteXml(Server.MapPath("database.xml"))

        dt.ReadXmlSchema(Server.MapPath("database.xsd"))
        dt.ReadXml(Server.MapPath("database.xml"))

        If DropDownList1.SelectedValue = 0 Then
            ds.Tables(0).Merge(dt)
            rptDoc.Load(Server.MapPath("SimpleCrystal.rpt"))
            rptDoc.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rptDoc

        ElseIf DropDownList1.SelectedValue = 1 Then
            ds.Tables(0).Merge(dt)
            rptDoc.Load(Server.MapPath("GroupCrystal.rpt"))
            rptDoc.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rptDoc

        ElseIf DropDownList1.SelectedValue = 2 Then
            ds.Tables(0).Merge(dt)
            rptDoc.Load(Server.MapPath("Graph.rpt"))
            rptDoc.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rptDoc

        ElseIf DropDownList1.SelectedValue = 3 Then
            ds.Tables(0).Merge(dt)
            rptDoc.Load(Server.MapPath("CrossTab.rpt"))
            rptDoc.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rptDoc

        ElseIf DropDownList1.SelectedValue = 4 Then
            ds.Tables(0).Merge(dt)
            rptDoc.Load(Server.MapPath("SubReport.rpt"))
            rptDoc.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rptDoc

        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions