Skip to Content

Get Parameter value from ReportViewer

I am using Visual Studio 2010 with Crystal Report for .NET version 13.0.2000.0. I have a Crystal Report Viewer Control as the only item on a page and I am opening a report where the Crystal Report Viewer Control prompts me for the parameters.

My code to do this looks like this:

Protected Sub ViewReport(strReport As String)

Dim crReportDocument As New CrystalDecisions.Web.CrystalReportSource

crReportDocument.Report.FileName = strReport

crReportDocument.ReportDocument.FileName = strReport

Me.CrystalReportViewer1.ReportSource = crReportDocument

Me.CrystalReportViewer1.EnableParameterPrompt = True

'Me.CrystalReportViewer1.EnableDatabaseLogonPrompt = True

Me.CrystalReportViewer1.EnableDatabaseLogonPrompt = False

Me.CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None

'Me.CrystalReportViewer1.LogOnInfo(0).ConnectionInfo.UserID = "userid"

'Me.CrystalReportViewer1.LogOnInfo(0).ConnectionInfo.Password = "password"

For i As Integer = 0 To Me.CrystalReportViewer1.LogOnInfo.Count - 1

Select Case Me.CrystalReportViewer1.LogOnInfo(i).ConnectionInfo.ServerName.ToLower

Case "prod"

Me.CrystalReportViewer1.LogOnInfo(i).ConnectionInfo.UserID = "prod"

Me.CrystalReportViewer1.LogOnInfo(i).ConnectionInfo.Password = "password"

Case "test"

Me.CrystalReportViewer1.LogOnInfo(i).ConnectionInfo.UserID = "test"

Me.CrystalReportViewer1.LogOnInfo(i).ConnectionInfo.Password = "password"

Case Else

Me.CrystalReportViewer1.EnableDatabaseLogonPrompt = True

End Select


Session("ReportDoc") = crReportDocument

End Sub

This all works wonderfully. It prompts me for my parameters, I enter them and it displays the report.

However, I now need to be get the parameter value that the user entered when they were prompted, and the name of the parameter too. I have tried the following which will give me the parameter names, but I cannot get the value to display. It always errors at the point in red below, when it is trying to get the current value. Can someone please help?

Private Sub GetParams()

Dim ReportDoc = CType(Session("ReportDoc"), CrystalDecisions.Web.CrystalReportSource)

Dim ParamDef As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions

ParamDef = ReportDoc.ReportDocument.DataDefinition.ParameterFields

For Each Param As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition In ParamDef

Dim CurVal As CrystalDecisions.Shared.ParameterValues

CurVal = Param.CurrentValues

Dim DesVal As CrystalDecisions.Shared.ParameterDiscreteValue

Debug.WriteLine("Parameter Name: " & Param.Name)

DesVal = CurVal.Item(0)

Debug.WriteLine(Param.Name & ":" & DesVal.Value)


End Sub

Thank you in advance,


Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 31, 2012 at 01:38 PM

    Try this ,

    crReportDocument= New ReportDocument


    crReportDocument.SetParameterValue("Report Parameter Name ", Param.Name)

    CrystalReport.HasToggleParameterPanelButton = False

    CrystalReport.ToolPanelView = ToolPanelViewType.None

    CrystalReport.ReportSource = crReportDocument

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 31, 2012 at 08:44 PM

    I guess I will go the route of building my own parameter prompts.

    Thanks to everyone who responded.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.