locked
Passing Parameter Value to Crystal Reports in VS2010 RRS feed

  • Question

  • I recently upgraded a reporting application from VS2008 to VS2010 (w/ CR 2010). I am running into problems passing the parameter values. Everything was working great with this code in VS2008... I'm wondering why this isn't working in VS2010??? The reports w/o parameters are working in VS2010 it's just a problem if the report has parameters.

    When I try to generate a report w/ parameters it opens a prompt asking to input the values even though I pass them in the code. Here is the main part of the code, let me know fi you need more info:

     Dim intCounter As Integer
     Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
     Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
     Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
     Dim currValue As CrystalDecisions.Shared.ParameterValues
     Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
     Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
     Dim strParValPair() As String
     Dim strVal() As String
     Dim sFileName As String
     Dim index As Integer
    
     Try
    
      objReport.Load(ReportFileName)
    
      ConInfo.ConnectionInfo.UserID = "ReportUser"
      ConInfo.ConnectionInfo.Password = "password-removed"
      ConInfo.ConnectionInfo.ServerName = "my-server"
      ConInfo.ConnectionInfo.DatabaseName = "rptDB"
      objReport.SetDatabaseLogon("ReportUser", "password-removed", "my-server", "rptDB")
    
      For intCounter = 0 To objReport.Database.Tables.Count - 1
      objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
      Next
    
      intCounter = objReport.DataDefinition.ParameterFields.Count
      If intCounter = 1 Then
      If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
       intCounter = 0
      End If
    
      End If
    
      'PASS PARAMETER VALUES HERE ***************
      If intCounter > 0 And Trim(param) <> "" Then
      strParValPair = param.Split("&")
    
      For index = 0 To UBound(strParValPair)
       If InStr(strParValPair(index), "=") > 0 Then
       strVal = strParValPair(index).Split("=")
       paraValue.Value = strVal(1)
       currValue = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
       currValue.Add(paraValue)
       objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue)
       objReport.SetParameterValue(index, strVal(1))
       End If
    
      Next
    
      End If
    
      If sSelectionFormula.Length > 0 Then
      objReport.RecordSelectionFormula = sSelectionFormula
      End If
    
      rptViewer.ReportSource = Nothing
      rptViewer.ReportSource = objReport
    
      rptViewer.Show()
    
    Catch ex As System.Exception
      MsgBox(ex.Message)
     End Try
    
    
    
    
    Wednesday, June 2, 2010 3:21 PM

Answers

  • Even stranger is the fact that when I set it to xport to pdf instead of the CrystalReportViewer it works fine w/ no parameter prompt. Which leads me to believe that there is a problem with the viewer?
    • Proposed as answer by Eli Candido Jr Friday, June 4, 2010 8:06 PM
    • Marked as answer by Harry Zhu Monday, June 7, 2010 7:11 AM
    Wednesday, June 2, 2010 6:53 PM
  • So I figured out why this is happening. When it asks you "convert" the project crystal report controls to the 2010 version of the CR dlls. It adds...
    Private Sub frmViewReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.rptViewer.RefreshReport()
    End Sub

    Basically this refreshes the viewer onLoad. They seem to assume that you are going to be setting parameters AFTER the form loads, which I would think is a backwards assumption. They should at least warn you that they are going to be modifying the functionality in the conversion log..

    The documentation on this was very poor, thank you crystal reports for wasting my morning! I hope this is helpful for anyone else who runs into this problem.

    • Marked as answer by Harry Zhu Monday, June 7, 2010 7:11 AM
    Wednesday, June 2, 2010 8:03 PM

All replies

  • Even stranger is the fact that when I set it to xport to pdf instead of the CrystalReportViewer it works fine w/ no parameter prompt. Which leads me to believe that there is a problem with the viewer?
    • Proposed as answer by Eli Candido Jr Friday, June 4, 2010 8:06 PM
    • Marked as answer by Harry Zhu Monday, June 7, 2010 7:11 AM
    Wednesday, June 2, 2010 6:53 PM
  • So I figured out why this is happening. When it asks you "convert" the project crystal report controls to the 2010 version of the CR dlls. It adds...
    Private Sub frmViewReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.rptViewer.RefreshReport()
    End Sub

    Basically this refreshes the viewer onLoad. They seem to assume that you are going to be setting parameters AFTER the form loads, which I would think is a backwards assumption. They should at least warn you that they are going to be modifying the functionality in the conversion log..

    The documentation on this was very poor, thank you crystal reports for wasting my morning! I hope this is helpful for anyone else who runs into this problem.

    • Marked as answer by Harry Zhu Monday, June 7, 2010 7:11 AM
    Wednesday, June 2, 2010 8:03 PM
  • thanks, that was very helpful to me !
    ECJ
    Friday, June 4, 2010 8:06 PM
  • hi

    i also convert my win form app in VS 2010 from VS 2008

    i m also facing the similar problem.

    but just adding Me.rptViewer.RefreshReport() did't help me ..

    i remove report viewer control from my page and add it again..

     

    this solve my problem..

     

    thanks a lot..

    Friday, October 8, 2010 5:53 PM
  • The same as  happened to me:

    converted the VS 2008 VB application (which worked fine) to VS2010 VB and after that the parametered reports didn't work.

    So i followed  @Patibandha's  advice and it worked: removing the old report viewer control and adding it back again did the trick!

    Thanks very much!

    Monday, February 28, 2011 5:00 PM
  • Thanks Patibandha!  i was worried this issue was going to take a few days to resolve...
    Holden
    Monday, April 25, 2011 3:47 PM
  • Thanks Patibandha! that solved the issue.
    Thursday, June 30, 2011 12:31 PM