Skip to Content
0
Jul 30, 2012 at 07:46 PM

Get Parameter value from ReportViewer

252 Views

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

Next

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)

Next

End Sub

Thank you in advance,

Andrew