Solved

Pass in Parameter Value:  VB.NET ASP.NET

Posted on 2004-08-09
3
8,509 Views
Last Modified: 2009-04-15
I am trying to pass a parameter value in from a textbox - right now am tryign to settle for hardcoding the param value and getting the report tp pick it up - here is the code that I am using now:
------------------------------------------
    Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Dim crReportDocument As DiscreteParam
        Dim crParameterFields As CrystalDecisions.Shared.ParameterFields
        Dim crParameterField As CrystalDecisions.Shared.ParameterField
        Dim crParameterValues As CrystalDecisions.Shared.ParameterValues
        Dim crParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue

        ''Create an instance of the strongly-typed report object
        'crReportDocument = New DiscreteParam()

        ''The viewer's reportsource must be set to a report before any
        ''parameter fields can be accessed.
        'CrystalReportViewer1.ReportSource = "C:\WebSites\WebSite3\rptEffectDateExcept.rpt"

        ''Get the collection of parameters from the report
        crParameterFields = CrystalReportViewer1.ParameterFieldInfo

        ''Access the specified parameter from the collection
        crParameterField = crParameterFields.Item("@prmMonth")

        ''Get the current values from the parameter field.  At this point
        ''there are zero values set.
        'crParameterValues = crParameterField.CurrentValues
        crParameterValues = crParameterField.DefaultValues
        ''Set the current values for the parameter field

        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
        crParameterDiscreteValue.Value = "1.00"

        ''Add the first current value for the parameter field
        crParameterValues.Add(crParameterDiscreteValue)

        ''Set the modified parameters collection back to the viewer so that
        ''the new parameter information can be used for the report.
        CrystalReportViewer1.ParameterFieldInfo = crParameterFields


        CrystalReportViewer1.ReportSource = "C:\WebSites\WebSite3\rptEffectDateExcept.rpt"
    End Sub
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 11759318
0
 
LVL 1

Accepted Solution

by:
NissePPP earned 500 total points
ID: 11760933
Here are an ex. how to pass a text to a Textfield in CR ( no parameterfield)

    Public Function add2textfield()
        Dim CR As New ReportDocument
        Dim temp As String
        'The loaction of the report
        temp = "C:\\WindowsApplication1\CrystalReport3.rpt"
        CR.Load(temp)

        Try
            Dim myReportTextObject As CrystalDecisions.CrystalReports.Engine.TextObject
            Dim myTestObject As CrystalDecisions.CrystalReports.Engine.ReportObject

            'The name of the textfield in CR: DescriptionText
            If TypeOf CR.ReportDefinition.ReportObjects.Item("DescriptionText") Is CrystalDecisions.CrystalReports.Engine.TextObject Then
             
                'The text that you want to show in your textfield
                CType(CR.ReportDefinition.ReportObjects.Item("DescriptionText"), _
                      CrystalDecisions.CrystalReports.Engine.TextObject).Text = _
                      "TEST"

            End If
        Catch err As Exception
            'the description text in the document won't be written
        End Try

        CrystalReportViewer1.ReportSource = CR
    End Function
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11762002
You are using the viewer object model. iT is limited if you want to use some other runtime customizations. I would offer to use runtime customization with report engine object model. I use it all the time and it works. Here is the code that I wrote for parameters in report engine object model in C#. Convert it to VB.net

................
private  CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition SetReportParameters(CrystalDecisions.CrystalReports.Engine.ReportDocument MyReport)
      {
                  //sets the parameter values for main report and sub reports if any
      CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition ParameterFieldDefinition;
      CrystalDecisions.Shared.ParameterDiscreteValue  ParameterDiscreteValue;
      CrystalDecisions.Shared.ParameterValues  ParameterValues;                              
      int paramcount;
      paramcount = this.MyParameterValues.Count;
      ParameterFieldDefinition = null;
                                    
      for (int i = 0; i != paramcount; i++)//have to put paramcount otherwise hard code it .works
          {
                                                      ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields[i];  
      ParameterValues = new CrystalDecisions.Shared.ParameterValues();
      ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
      ParameterDiscreteValue.Value = this.MyParameterValues[i];      
      ParameterValues.Add(ParameterDiscreteValue);
      ParameterFieldDefinition.CurrentValues.Clear();
      ParameterFieldDefinition.DefaultValues.Clear();  
      ParameterFieldDefinition.ApplyCurrentValues(ParameterValues);
                        
       }            
      return ParameterFieldDefinition;
                                                
      }
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question