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
|
Goran Level: Moderator Registered: 16-05-2002 Posts: 1681
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.
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
|
Goran Level: Moderator Registered: 16-05-2002 Posts: 1681
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: