This sample code shows how to load the report to CrystalReportHelper and set up the database connection/ parameter, as well as printer and export the report as PDF and print out the report

// multi-line
   Imports CrystalReportHelperLib

Private Sub btn_GenerateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_GenerateReport.Click
        'Create a Crystal Report Helper instance
        Dim CReport As New CrystalReportHelper
        Using CReport
            'Initialise the Crystal report Helper with a Crystal Report file .rpt
            CReport.InitialiseCrystalReport("C:\CrystalReport\ShareChiWaiSample.rpt")
            'Set up datebase connection
            CReport.SetDataSourceConnection("SQL Server Name", "SQL Database Name", "SQLUsername", "SQLPW")
            'Set up printer setting to print in Duplex
            CReport.SetPrinterSettingsDuplexDefaultOption()
            'Assign printer for printing the report
            CReport.SetPrinter("Printer Path\Printer Name")
            'Assign Reports/Database variable
            CReport.SetParameter("@Period", "Database Variable1")
            CReport.SetParameter("@Period", "Database Variable1")

            'Export PDF
            CReport.ExportCrystalReport("PortableDocFormat", "C:\CrystalReport\Export\ShareChiWaiSample.pdf")

            'Print Report
            CReport.PrintAllDoc()
            'Close the report to release resource
            CReport.Close()
            CReport = Nothing
        End Using
    End Sub



Hope you find it useful

Last edited Nov 15, 2010 at 11:04 PM by sharechiwai, version 1

Comments

No comments yet.