Question how to pass parameters of a Stored Procedure used as data source by a CR

zakaryahelal

Member
Joined
Mar 23, 2009
Messages
6
Programming Experience
Beginner
My question is how to pass the required parameters of a Stored Procedure that is being used as data source by a CR report
I have a report written in the version of crystal reports that ships with vb.net 2008.
The report links to a stored procedures. which has a DateFrom (DateTime) and DateTo (DateTime) parameters

I passed these parameters through code when loading the report viewer to avoid requesting each necessary parameter for execute the Store Procedure

But every time run the report a dialog appear to request both parameters for execute the Store Procedure.

This Code I am using

VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        txtFromDate = Format(Me.DateFrom.Value, "dd/MM/yyyy")
        txtToDate = Format(Me.DateTo.Value, "dd/MM/yyyy")
        Dim F As New FrmPrint
        Dim rpt As New CrystalReport1


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

        crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields
        crParameterDiscreteValue.Value = txtFromDate
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("@DateFrom")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        crParameterDiscreteValue.Value = txtToDate
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("@DateTo")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        GETSERVERNAMEANDDATABASENAME(rpt, "", "", "")
        Formula = "{Brokers;1.BrokerUserID} = " & Broker.SelectedValue & ""
        rpt.RecordSelectionFormula = Formula
        F.CrystalReportViewer1.ReportSource = rpt
        F.CrystalReportViewer1.Zoom(92%)
        F.CrystalReportViewer1.RefreshReport()
        F.Show()

Any ideas?
thanks in advance
 

Latest posts

Back
Top