Site Search:
Sign in | Join | Help

This Blog

Syndication

Tags

No tags have been created or used yet.

Crystal Reports

Notes, Tips and Tricks on Developing using Crystal Reports
  • VS 2008 Changing a datasource at runtime

    This is a walk through for changing the datasource of a VS 2008 Crystal Report at runtime.

    Create a new form in VB, add the Crystal Report Viewer control, dock it. For the sake of simplicity, I've kept the code as concise as possible. The form has two public properties, the report name and the data source. We pass those in before opening the form.

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    
    
    Public Class ReportCrystal
        Dim crDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    
    
        'public variables
        Public ReportName As String
        Public ReportDataTable As DataTable
    
    
    
        Private Sub ReportCrystal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim strStartupPath As String = Application.StartupPath
            strStartupPath += "\reports\" & Me.ReportName
            crDoc.Load(strStartupPath)
            crDoc.SetDataSource(ReportDataTable)
            Me.CrystalReportViewer1.ReportSource = crDoc
        End Sub
    End Class

    So, the report is called like this. Naturally there will be parameters, but that is not covered here.

    Private Sub btnPrintTickets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintTickets.Click
        Dim frm As New ReportCrystal
    
    
        frm.ReportName = "PickingTickets.rpt"
        'code to populate a datatable. This code uses my custom data access classes, but any data access code will do. 
        frm.ReportDataTable = SPs.sp_SOP10200_SEL_bySopnumbe(Me.Orders, Me.txtPalletID.Text, Me.chkOptimize.Checked, AppUser.Database).getTable
    
    
        frm.ShowDialog()
    End Sub

  • 'CrystalReportViewer' is ambiguous in the namespace 'CrystalDecisions.Web'

    Also:

    Error 13 'ReportDocument' is ambiguous in the namespace 'CrystalDecisions.CrystalReports.Engine'. C:\projects\Culinart\Culinart\Reports\POSCash.aspx.vb 11 18 C:\...\Culinart\

    Error 15 'DiskFileDestinationOptions' is ambiguous in the namespace 'CrystalDecisions.Shared'. C:\projects\Culinart\Culinart\Reports\POSCash.aspx.vb 47 26 C:\...\Culinart\

    Error 16 'ExportDestinationType' is ambiguous in the namespace 'CrystalDecisions.Shared'. C:\projects\Culinart\Culinart\Reports\POSCash.aspx.vb 50 57 C:\...\Culinart\

    Error 17 'ExportFormatType' is ambiguous in the namespace 'CrystalDecisions.Shared'. C:\projects\Culinart\Culinart\Reports\POSCash.aspx.vb 51 52 C:\...\Culinart\

    I solved this by going to Project Propertities > References, somehow I had references to two different versions of crystal in my project. While doing this I noticed that the references kept coming back. I searched the project and found that I had double lines iin the web config to different versions of Crystal.

     

  • Crystal in VB Deployment Projects (Visual Studio 2008)

    In Visual Studio 2008, merge modules are no longer used for crystal reports controls.

     To add the crystal reports files:

    1.  Go to the deployment project's properties page.
    2.  Click the "Prerequisites" button.
    3.  Add the "Crystal Reports Basic for Visual Studio 2008"

    It may also require the "Windows Installer 3.1"

More Posts Next page »