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
Solved

Pass in Parameter Value:  VB.NET ASP.NET

Posted on 2004-08-09
3
8,500 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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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