Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. trouble in passing parameter in crystal document

trouble in passing parameter in crystal document

Scheduled Pinned Locked Moved Visual Basic
helpcomdata-structurestutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aguest
    wrote on last edited by
    #1

    i am getting some trouble with a tutorial that i found on msdn web site : http://msdn.microsoft.com/en-us/library/ms227722.aspx. i would like to pass a parameter to my CrystalReport document,but i would like to send an integer value to my CR document and just one value(because in the tut its sending and array of string values). the code is the fellowing

    Private Const PARAMETER_FIELD_NAME As String = "numb"

    Private impbonrecepReport As ReportDocument
    
    Private Sub ConfigureCrystalReports()
    
    
        Dim myArrayList As ArrayList = New ArrayList()
    
        myArrayList.Add(999)
        Dim numbrecep As Integer
    
        numbrecep = 999
    
    
    
        SetCurrentValuesForParameterField(impbonrecepReport, myArrayList)
       
        impbonrecepReport = New ReportDocument()
        Dim reportPath As String = Application.StartupPath & "\\" & "ImpBonReception.rpt"
    
        impbonrecepReport.Load(reportPath)
        CrystalReportViewer1.ReportSource = impbonrecepReport
    
    End Sub
    

    Private Sub SetCurrentValuesForParameterField(ByVal myReportDocument As ReportDocument, ByVal myArrayList As ArrayList)

        Dim currentParameterValues As ParameterValues = New ParameterValues()
    
    
        For Each submittedValue As Object In myArrayList
    
            Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
            myParameterDiscreteValue.Value = myArrayList.ToString()
            currentParameterValues.Add(myParameterDiscreteValue)
    
        Next
    
    
        Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
        Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER\_FIELD\_NAME)
        myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues)
    
    
    End Sub
    

    i got this error message

    An unhandled exception of type 'System.NullReferenceException' occurred in GestionStock.exe
    Additional information: La référence d'objet n'est pas définie à une instance d'un objet.

    in this line Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields can you help me to solve this problem? thank you

    T 1 Reply Last reply
    0
    • A aguest

      i am getting some trouble with a tutorial that i found on msdn web site : http://msdn.microsoft.com/en-us/library/ms227722.aspx. i would like to pass a parameter to my CrystalReport document,but i would like to send an integer value to my CR document and just one value(because in the tut its sending and array of string values). the code is the fellowing

      Private Const PARAMETER_FIELD_NAME As String = "numb"

      Private impbonrecepReport As ReportDocument
      
      Private Sub ConfigureCrystalReports()
      
      
          Dim myArrayList As ArrayList = New ArrayList()
      
          myArrayList.Add(999)
          Dim numbrecep As Integer
      
          numbrecep = 999
      
      
      
          SetCurrentValuesForParameterField(impbonrecepReport, myArrayList)
         
          impbonrecepReport = New ReportDocument()
          Dim reportPath As String = Application.StartupPath & "\\" & "ImpBonReception.rpt"
      
          impbonrecepReport.Load(reportPath)
          CrystalReportViewer1.ReportSource = impbonrecepReport
      
      End Sub
      

      Private Sub SetCurrentValuesForParameterField(ByVal myReportDocument As ReportDocument, ByVal myArrayList As ArrayList)

          Dim currentParameterValues As ParameterValues = New ParameterValues()
      
      
          For Each submittedValue As Object In myArrayList
      
              Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
              myParameterDiscreteValue.Value = myArrayList.ToString()
              currentParameterValues.Add(myParameterDiscreteValue)
      
          Next
      
      
          Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
          Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER\_FIELD\_NAME)
          myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues)
      
      
      End Sub
      

      i got this error message

      An unhandled exception of type 'System.NullReferenceException' occurred in GestionStock.exe
      Additional information: La référence d'objet n'est pas définie à une instance d'un objet.

      in this line Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields can you help me to solve this problem? thank you

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      The error is telling you that the object isn't initialized. And it is right. Change your code to the following:

          impbonrecepReport = New ReportDocument()
          Dim reportPath As String = Application.StartupPath & "\\" & "ImpBonReception.rpt"
      impbonrecepReport.Load(reportPath)
      

      SetCurrentValuesForParameterField(impbonrecepReport, myArrayList)

          CrystalReportViewer1.ReportSource = impbonrecepReport
      

      Initialize and load your report first, then set the parameter value's and then show it. You'll also have to change

      ByVal myReportDocument As ReportDocument

      to

      ByRef myReportDocument As ReportDocument

      Or make the sub into a function and return the report at the end. Basicly you passed an empty object to the 'SetCurrentValuesForParameterField'.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups