on 07-30-2012 8:46 PM
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
Try this ,
crReportDocument= New ReportDocument
crReportDocument.Load(Server.MapPath("Reportname.rpt"))
crReportDocument.SetParameterValue("Report Parameter Name ", Param.Name)
CrystalReport.HasToggleParameterPanelButton = False
CrystalReport.ToolPanelView = ToolPanelViewType.None
CrystalReport.ReportSource = crReportDocument
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for responding....
However, I don't want to set my parameters via code. I want to let the Crystal Report Viewer Control prompt the user and let them fill in the values, but I want to collect the values they enter so that I can place them into a table for audit purposes.
My main issue is that when I try to get the parameters they enter the currentvalues property of ParameterFieldDefinition is always empty even though I just entered a value for this parameter via the prompt.
Thanks,
Hi Andrew,
I suggest you develop your own custom parameter prompt before the actual CR parameter prompt, let the users enter the values in the custom prompt built by you, which you can easily gather and store in the DB. then pass those values entered by the user to the report through code.
Hope this helps,
Bhushan
I agree with Andrew. I don't see any APIs exposed off of the viewer that would let you do a Get on the entered parameters.
See:
SAP Crystal Reports .NET API Guide
SAP Crystal Reports .NET SDK Developer Guide
- Ludek
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
I guess I will go the route of building my own parameter prompts.
Thanks to everyone who responded.
-Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.