Title: How to pass parameters to Crystal reports?
Tags: vb.net;parameters;crystal-reports-2010
Question: I am trying to filter customers using a parameter in Crystal, by typing a customer code in a textbox. I created a parameter for the customer code, and tried to pass it's value using the code shown below, but it is not working. When I click on the button it is showing all customers not only the filtered ones:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class ParametroCrForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim relatorio As New ReportDocument
relatorio.Load("C:\Users\Fernando e Flavia\Documents\Visual Studio 2010\Projects\Crystal.Estudo\Crystal.Estudo\CrystalReport1.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
If codigoTextBox.Text = "" Then
MessageBox.Show("Digite um c�digo de cliente", "Aten��o", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If
crParameterDiscreteValue.Value = codigoTextBox.Text
crParameterFieldDefinitions = relatorio.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("codigoParametro")
crParameterValues.Clear()
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = relatorio
CrystalReportViewer1.Refresh()
End Sub
End Class
Comment: Did you create a selection formula in your report based on that parameter?

Comment: No, I haven't I am really new in codding, I didn' know about that additional step, It worked!! Thank you very much!!!!


Here is another answer: According to explanation from ABZY, I had to add selection formula in my report.
In the link below it is explained how to do that:
http://vb.net-informations.com/crystal-report/vb.net_crystal_report_parameter_string.htm
Thanks again Abzy!!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:01/13/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<vb.net><parameters><crystal-reports-2010>', 'Title': 'How to pass parameters to Crystal reports?', 'ViewCount': 1915, 'id': 14304668, 'user_AboutMe': None, 'user_AccountId': 2132908.0, 'user_DisplayName': 'Fernando', 'user_Reputation': 33.0, 'user_Views': 8.0, 'user_id': 1893296.0}}