locked
Pass Crystal Report as a parameters RRS feed

  • Question

  • Hi,
    I need to pass the name of a crystal report as a parameter but how do you then change this string into a report name?? or even better still how do you pass  the crystal report as a parameter??

    Cheers
    Thursday, April 12, 2007 1:07 PM

Answers

  • shax,

     

    Please try the following code:

     

    Code Snippet

    Imports CrystalDecisions.CrystalReports.Engine

    Class Class1

        ' Create report instance. This is the class added to your project

        ' when you added the report to the project

        Dim report As MyReport = New MyReport

        ' Fill data in DataSet here. Skip this step if your report is calling

        ' a stored procedure direct

        Dim ds As DataSet = New DataSet

        ' ds = GetDataFromDatabase()

        Dim crParameterDiscreteValue As ParameterDiscreteValue

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions

        Dim crParameterFieldLocation As ParameterFieldDefinition

        Dim crParameterValues As ParameterValues

        '

        ' Get the report parameters collection.

        '

    crParameterFieldDefinitions = report.DataDefinition.ParameterFields

        ' Add a parameter value - START

    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName1")

    crParameterValues = crParameterFieldLocation.CurrentValues

    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue

    crParameterDiscreteValue.Value = "Parameter1Value"

    crParameterValues.Add(crParameterDiscreteValue)

    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)

        ' Add a parameter value - END

    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName2")

    crParameterValues = crParameterFieldLocation.CurrentValues

    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue

    crParameterDiscreteValue.Value = "Parameter2Value"

    crParameterValues.Add(crParameterDiscreteValue)

    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)

        '

        ' Set report's DataSource. Skip this step if your report is calling a

        ' stored procedure direct in the report.

        '

    report.SetDataSource(ds)

        '

        ' Set CrystalReportViewer.ReportSource

        '

    CrystalReportViewer1.ReportSource = report

    End Class

     

    For further information on the issue, please take a look at the following link:

     

    http://www.c-sharpcorner.com/UploadFile/mahesh/paramInCR11012006132839PM/paramInCR.aspx

    Thursday, April 19, 2007 3:50 AM