Quantcast
Viewing all articles
Browse latest Browse all 1507

Cannot Pass Parameters from code to Crystal Reports

This is the first time I've ever used Crystal Reports, and it shows.

In a seperate page, I select a row from a gridview and click a button to print that particular report.

The Querystring passes that value, the contract number, to the report page. 

In the rpt, I have a database field ContractNumber and have created a Crystal Reports parameter, @ContractNumber, and associated those in the record selection formula.

The associated code is:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim crystalReport As New ReportDocument()
        crystalReport.Load(Server.MapPath("FC15ContractPrint.rpt"))
        CrystalReportViewer1.ReportSource = crystalReport
        HiddenField1.Value = Request.QueryString("ContractNumber")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = HiddenField1.Value
        crParameterFieldDefinitions = crystalReport.DataDefinition.ParameterFields()
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("@ContractNumber")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewer1.RefreshReport()
    End Sub

It keeps asking me to manually input the parameter, though.

 


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>