Solved

Pass in Parameter Value:  VB.NET ASP.NET

Posted on 2004-08-09
3
8,493 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now