Results 1 to 3 of 3

Thread: VB<->Crystal Report

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    16

    VB<->Crystal Report

    Does any body know how to pass a paramter value to a stored procedure in crystal reports thru vb coding.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB<->Crystal Report

    Moved from the CodeBank

  3. #3
    Junior Member Coke's Avatar
    Join Date
    Mar 2007
    Posts
    31

    Re: VB<->Crystal Report

    This is the code for passing the items choose at runtime for searching in CR! (edit accordingly to make it work for your program)


    Code:
    ' Create report instance. This is the class added to your project
    
    ' when you added the report to the project
    
    Dim report As MyReport = New MyReport
    
     
    
    ' Fill data in DataSet here. Skip this step if your report is calling 
    
    ' a stored procedure direct 
    
    Dim ds As DataSet = New DataSet
    
    ' ds = GetDataFromDatabase()
    
     
    
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    
    Dim crParameterFieldLocation As ParameterFieldDefinition
    
    Dim crParameterValues As ParameterValues
    
            
    
    '
    
    ' Get the report parameters collection. 
    
    '
    
    crParameterFieldDefinitions = report.DataDefinition.ParameterFields
    
     
    
    ' Add a parameter value - START
    
    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName1")
    
    crParameterValues = crParameterFieldLocation.CurrentValues
    
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    
    crParameterDiscreteValue.Value = "Parameter1Value"  
    
    'if you want to choose the value from a combobox for example, just change the "Parameter1Value" to "cboName.selecteditem". So the selected item will be pass in.
    
    crParameterValues.Add(crParameterDiscreteValue)
    
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
    
    ' Add a parameter value - END
    
     
    
    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName2")
    
    crParameterValues = crParameterFieldLocation.CurrentValues
    
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    
    crParameterDiscreteValue.Value = "Parameter2Value"
    
    crParameterValues.Add(crParameterDiscreteValue)
    
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
    
     
    
    '
    
    ' Set report's DataSource. Skip this step if your report is calling a 
    ' stored procedure direct in the report.
    
    '
    
    report.SetDataSource(ds)
    
     
    
    '
    
    ' Set CrystalReportViewer.ReportSource
    
    '
    
     
    
    CrystalReportViewer1.ReportSource = report

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width