borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (report show as per date short by number type field in ascending order)Next Topic (Draft Mode Printing on CR8) New Topic New Poll Post Reply
AndreaVB Forum : Reporting tools : Sending values to crystal report parameterfields from vb .NET program
Poster Message
goldenmusketeer
Level: Whizz Kid


Registered: 23-12-2004
Posts: 16

icon Sending values to crystal report parameterfields from vb .NET program

Hello Guys,
          I am developing a database-application in VB.NET 2005. I have designed a report in crystal report(RptEmployee.rpt), which have a parameterfield named "company".
          Now , my question is how to send value to this parameter from my VB .NET program.


Previously in VB and crystal report 8.5 I used to write ---
   crystalreport1.parameterfields(0)="company;" & trim(txtcompany.text) & ";true"  

Question is how to do this thing in VB. NET 2005  



[Edited by goldenmusketeer on 07-04-2006 at 12:04 AM GMT]

____________________________
.....Joy

06-04-2006 at 07:02 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Sending values to crystal report parameterfields from vb .NET program

Try this parameters collection

CR.DataDefinition.ParameterFields

____________________________
If you find the answer helpful, please mark this topic as solved.

07-04-2006 at 11:28 AM
View Profile Send Email to User Show All Posts | Quote Reply
goldenmusketeer
Level: Whizz Kid


Registered: 23-12-2004
Posts: 16
icon Re: Sending values to crystal report parameterfields from vb .NET program

Hey Guys,
     I wrote this Code....




    
Private Sub printReport1()
        Dim rpt As New ReportDocument
        Dim frmObj As New frmReportViewer
        Dim FileName As New String(Application.StartupPath & "\RptEmployee.rpt")

        rpt.Load(FileName)

        'Use of selection formula to filter records
        If chkShowAll.Checked = False Then
            rpt.DataDefinition.RecordSelectionFormula = "{Emp.name} like '" & Trim(txtName.Text) & "*'"
        End If
        '##############################
         'Use of parameter passing from program
        'The Parameters in the report
        Dim Params As New CrystalDecisions.Shared.ParameterField
        'A collection of parameters is a parameter field
        Dim ParamCollection As New CrystalDecisions.Shared.ParameterFields
        'Every parameter has a descrete value
        Dim ParamDisVal As New CrystalDecisions.Shared.ParameterDiscreteValue()
        'Now each of these parameters should be added a meaning
        Params.ParameterFieldName = "user"
        'Each of these parameters should be given a starting value
        ParamDisVal.Value = "Created Joy Acharyya"
        'All these values should be added to parameter field
        Params.CurrentValues.Add(ParamDisVal)
        'Finally all these parameters should be added to the report
        ParamCollection.Add(Params)
        '###############################

        With frmObj
            .crViewer.ReportSource = rpt
            'ParameterInfo has been given all the information needed
            .crViewer.ParameterFieldInfo = ParamCollection
            .ShowDialog()
        End With
    End Sub


But here after the crviewer is loaded an error is thrown "Incorrect parameter" but the name of the parameter is correct

I wrote another one ----



Private Sub printReport2(ByVal ReportObj As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal ParamName() As String, ByVal ParamValues() As String)
        Dim myRptObj As CrystalDecisions.CrystalReports.Engine.ReportDocument = ReportObj
        Dim field As CrystalDecisions.Shared.ParameterValues
        Dim Value As CrystalDecisions.Shared.ParameterDiscreteValue

        Try
            If Not ParamName Is Nothing Then
                For i As Integer = 0 To ParamName.Length - 1
                    field = New CrystalDecisions.Shared.ParameterValues
                    Value = New CrystalDecisions.Shared.ParameterDiscreteValue
                    Value.Value = ParamValues(i)
                    field.Add(Value)
                    myRptObj.DataDefinition.ParameterFields(ParamName(i)).ApplyCurrentValues(field)

                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Print Error")

        End Try
    End Sub



I called the above report in this way---


Dim rptobj As New ReportDocument
        Dim paramName() As String = {"user"}
        Dim paramValues() As String = {"Coded by goldenmusketeer"}
        rptobj.Load(Application.StartupPath & "\RptEmployee.rpt")
        Call printReport2(rptobj, paramName, paramValues)


*But here also a COM exception is thrown



HELP me out..Don't know how to solve it


                                    

____________________________
.....Joy

08-04-2006 at 06:18 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Sending values to crystal report parameterfields from vb .NET program

How did you create parameter in CR? If using Parameter Fields node in the Crystal IDE's Field Explorer, then you can use this code:

Dim rpt As New ReportDocument

    rpt.Load(FileName)
    rpt.SetDataSource(ds.Tables("TableName"))
    rpt.SetParameterValue("ParameterName", ParameterValue)
    CrystalReportViewer.ReportSource = rpt


where ds is data set.

____________________________
If you find the answer helpful, please mark this topic as solved.

10-04-2006 at 04:19 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Reporting tools : Sending values to crystal report parameterfields from vb .NET program
Previous Topic (report show as per date short by number type field in ascending order)Next Topic (Draft Mode Printing on CR8) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder