How to pass parameter from code to crystal report

Posted by Thiru under VB.NET on 4/18/2012 | Points: 10 | Views : 20595 | Status : [Member] | Replies : 3
Hi,
I have created two parameters in crystal report (static parameters)
now, i just want to pass the values from code to crystal report.

purpose is: i just like to pass these two values from code to display it in crystal report.

How to do so?

regards,
Thiru.




Responses

Posted by: Sunny4989 on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
See the below code

Dim param1Fields As New ParameterFields

Dim param1Field As New ParameterField
Dim param1Range As New ParameterDiscreteValue

param1Field.ParameterFieldName = "sessiontype"
param1Range.Value = txtSessionType.Text
param1Field.CurrentValues.Add(param1Range)
param1Fields.Add(param1Field)
CrystalReportViewer1.ParameterFieldInfo = param1Fields


CrystalReportViewer1.ReportSource = "CrystalReport.rpt"
CrystalReportViewer1.Visible = True


------------------------------------------------
Learn throughout life

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply.
I am confused in using parameter.

I have mapped the required table and fields and design a report too.
and created 3 parameters: BranchCode, FromDate and ToDate

Need to display all records from BranchCode During the seleted period (From & To date)

Note: So for i have designed and passed the parameter from code to crystal report.

Now let me know how to show only the records which matching to these parameters ?

Expecting your valuable reply.
regards,
Thiru.



Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Markjeggar on: 5/31/2012 [Member] Starter | Points: 25

Up
0
Down
First step is to create a parameter field in crystal reports depends on your parameter datatype.

After creating the parameter field , you have to create the selection formula for the Crystal Reports .

and add following code

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue

crParameterDiscreteValue.Value = parametervalue
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("you field")
crParameterValues = crParameterFieldDefinition.CurrentValues

http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-string-parameter.htm
you can see thhis propgram with screen prints to create crstal reports.

mark.





Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response