Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Sep 22

Written by: Steve Gray
9/22/2010 12:01 PM  RssIcon

In order to call Crystal Reports in VB.NET, create a form and drop a CrystalReportViewer control onto the form. Copy this code into the form:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class CrystalReport
    Public ReportName As String
    Public DataSource As DataTable

    Dim crDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

    Private Sub CrystalReport_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load
        'before opening this form, the calling form must set the REPORTNAME 
‘and DATASOURCE properties
        Try
            If Me.ReportName = "" Then
                Exit Sub
            End If

            'load the report into Crystal
            Dim rpt As String
            rpt = "\\shareName\folderName\" & Me.ReportName
            crDoc.Load(rpt)

            'set the datasource
            crDoc.SetDataSource(Me.DataSource)


            'load the report into the report viewer
            CrystalReportViewer1.ReportSource = crDoc


        Catch ex As Exception
            'call the global error handler
            globalErrorHandler(ex)
        End Try

    End Sub

End Class
Before opening the form we need to set the ‘ReportName’ property of the form with the report name, and the ‘DataSource’ property with a datatable.

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us