Click here to Skip to main content
16,020,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not able to pass two parameter in crystal report. I can do with 1 parameter.
Please help, I want to pass another parameter in another textbox.
VB
Dim rpt As New CrystalReport_booking
Dim ReportPath As String = Application.StartupPath & "\CrystalReport_booking"
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues()
Dim crParameterDiscreteValue As New ParameterDiscreteValue()

crParameterDiscreteValue.Value = TextBox1.Text
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("bno")
crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

Catch ex As Exception
     MsgBox(ex.Message)
End Try
Posted
Updated 25-Apr-11 9:30am
v2
Comments
ZeeroC00l 25-Apr-11 14:15pm    
Do you have a database in your project?

Just create another parameter field in report. And in Code just copy-paste the 1st parameter thing & change it for second parameter.
VB
Dim rpt As New CrystalReport_booking
Dim ReportPath As String = Application.StartupPath & "\CrystalReport_booking"
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues()
Dim crParameterDiscreteValue As New ParameterDiscreteValue()
 
crParameterDiscreteValue.Value = TextBox1.Text
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("bno")
crParameterValues = crParameterFieldDefinition.CurrentValues

'Second parameter Coding 
crParameterDiscreteValue.Value = TextBox2.Text 'Second textbox
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("second")'Second parameter
crParameterValues = crParameterFieldDefinition.CurrentValues
 
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
 
Catch ex As Exception
     MsgBox(ex.Message)
End Try


For your information

VB.NET Crystal Reports String parameter[^]
 
Share this answer
 
Say for example your two text box contain some information related to date and you want to get the information between those two dates to display on the Crystal Report form.

The way you did above is one, and then there is one more easier way of doing the same.
The would be to use the ReportSource option

VB
Dim ds As New DataSet
Dim commandResult As OleDbCommand = New OleDbCommand("your querry based on the 2 fields applicable to the table")

commandResult.CommandType = 1
commandResult.Connection = cno
commandResult.ExecuteNonQuery()

Dim adapter As OleDbAdapter = New OleDbAdapter

adapter.SelectCommand=commandResult
adapter.Fill(ds)

Dim report As New CrystalReport1

report.SetDataSource(ds.Tables(0))

Form.CrystalReportViewer1.ReportSource=report
Form.CrystalReportViewer1.Refresh()


This is done assuming that you have done the rest of the things, like connecting to the Database and other necessary things successfully.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900