SAP Knowledge Base Article - Public

1375988 - How to set the parameter value to a Crystal report using the .NET Inproc RAS SDK

Symptom

How to set the parameter value to a Crystal report using the .NET Inproc RAS SDK.

Environment

  • Visual Studio 2005, 2008
  • Crystal Reports 2008

Resolution

Here the sample code to pass the parameter values to a Crystal report using the Report Client Document Object Model using Inproc RAS SDK.

C#.Net code

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.ReportAppServer.ClientDoc;
public partial class _Default : System.Web.UI.Page 
{
    ISCDReportClientDocument rcd;
    ReportDocument rd;
     protected void Page_Load(object sender, EventArgs e)
    {
        ConfigureReport();
    }
   
    void ConfigureReport()
        {
            rd = new ReportDocument();
            rd.Load(Server.MapPath("ReportWithParameter.rpt"));
            rcd = rd.ReportClientDocument;
            rcd.DataDefController.ParameterFieldController.SetCurrentValue("", "ParamPosition", "Mail Clerk");
            CrystalReportViewer1.ReportSource = rd;

        }
}

VB.Net code

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer.ClientDoc
Imports CrystalDecisions.ReportAppServer.DataDefModel
Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ConfigureCrystalReports()
    End Sub
    Private Sub ConfigureCrystalReports()
        Dim rd As ReportDocument = New ReportDocument
        rd.Load("C:\City.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
        Dim rcd As ISCDReportClientDocument
        rcd = rd.ReportClientDocument
        Dim values As New Values
        values.Add("Abu Dhabi")
        values.Add("Berlin")
        'Below line of code sets multiple values for discrete parameter
        rcd.DataDefController.ParameterFieldController.SetCurrentValues("", "City", values)
        'Below line of code sets single value for discrete parameter
        rcd.DataDefController.ParameterFieldController.SetCurrentValue("", "City", "Abu Dhabi")
        CrystalReportViewer1.ReportSource = rd
    End Sub
End Class

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

Crystal Reports 2008 V1