Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 15th, 2005, 03:13 AM
Authorized User
Join Date: Dec 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default How use the crystal report in vb.net

i want how connect crystal report in vb.net.
if want to use crystal report then what will have to do.
are it different from vb6.0 or not

Old February 26th, 2005, 03:03 AM
Registered User
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

You can programmatically pass parameter values into your Crystal Report using VB.NET code similar to this:

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    ' Load the selected report file.
    Dim CR As New ReportDocument
    ' Declare the parameter related objects.
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues
    ' Get the report's parameters collection.
    crParameterFieldDefinitions = CR.DataDefinition.ParameterFields
    ' Set the first parameter
    ' - Get the parameter, tell it to use the current values vs default value.
    ' - Tell it the parameter contains 1 discrete value vs multiple values.
    ' - Set the parameter's value.
    ' - Add it and apply it.
    ' - Repeat these statements for each parameter.
    crParameterFieldLocation = crParameterFieldDefinitions.Item("StartDate")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = strStartDate
    crParameterFieldLocation.ApplyCurrentValues(crPara meterValues)
    ' Set the Crytal Report Viewer control's source to the report document.
    CrystalReportViewer.ReportSource = CR

If your report's DataSource is a .NET DLL DO NOT set the ReportDocument's DataSource property programatically as in the code below. However, if the DataSource is an XML Schema (.xsd) file you must set it prior to setting your parameters.


If your report's DataSource is a .NET DLL as shown here and the public functions that return the datatables available to your report where changed to require parameters, as illustrated below, the parameters can be set as just described.

    Public Function Customers(theStartDate As String) As DataTable

If the parameters were added to your Crystal Report by clicking the Parameter Fields node in the Crystal IDE's Field Explorer they can be set using the following code:

    Dim cr As New ReportDocument
    cr.SetParameterValue("StartDate", strMyParmValue)
    CrystalReportViewer.ReportSource = cr
Old May 17th, 2013, 10:39 AM
Registered User
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default View Crystal Reports from .Net

I am using code like the following to view Crystal Reports from .Net

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim oApp = New CRAXDRT.Application
        Dim oReport As CRAXDRT.Report
        oReport = oApp.OpenReport("C:\temp\reportname.rpt", 1)

        With oReport.Database.Tables(1).ConnectionProperties
            .Add("Provider", "SQLOLEDB.1")
            .Add("User ID", "UserName")
            .Add("Password", "Password")
            .Add("Initial Catalog", "Database")
            .Add("DSN", "DSNName")

        End With

        AxCrystalActiveXReportViewer1.ReportSource = oReport

    End Sub

    Private Sub AxCrystalActiveXReportViewer1_Enter(sender As System.Object, e As System.EventArgs) Handles AxCrystalActiveXReportViewer1.Enter

    End Sub
End Class

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple report and crystal report in vb.net saket123 .NET Framework 2.0 0 August 13th, 2008 06:55 AM
vb.net And Crystal Report Tata .NET Framework 1.x 0 June 13th, 2008 10:16 PM
Crystal Report and VB.NET rupesh_india Beginning VB 6 0 August 19th, 2006 08:47 AM
Crystal Report in VB.net anandf Crystal Reports 1 March 13th, 2006 01:21 PM
Crystal Report in VB.Net mangeshshelar Crystal Reports 1 January 13th, 2005 09:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.