Solved

Pass in Parameter Value:  VB.NET ASP.NET

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

15 Experts available now in Live!

Get 1:1 Help Now