passing parameter to crystal report from vb.net

tutu

Member
Joined
Apr 17, 2006
Messages
12
Location
india
Programming Experience
1-3
hi all,
need code to pass bill no from my vb.net windows form to a crystal report so that the crystal report displays data from an sql server 2000 database depending on the bill no passes .
i specifically need the codes that are to be written in the code behind of the vb.net form ,i believe there is not much changes to be made on the crystal report .
it is a vb.net windows application and i am using crystal report 8.5 with sql server 2000 as the backend.
 
You need to have the parameter field in your crystal report to start with.

Then on your form you open the report from;
(this is how I do it, ReportNumber is a global variable which is set on each menu option, ParamValue is the ID I need for the report parameter, i.e. I set on the Report Open Click - ParamValue=textbox1.text)

VB.NET:
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ReportNumber = 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rpt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] REPORT_NAME_GOES_HERE
connection1.Open()
dataAdapter1.Fill(DataSet1.Table_Name)
rpt.SetDataSource(DataSet1)
rpt.SetParameterValue("PARAMETER_NAME", ParamValue)
crViewer.ReportSource = rpt
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MessageBox.Show(ex.Message)
[/SIZE][SIZE=2][COLOR=#0000ff]Finally
[/COLOR][/SIZE][SIZE=2]connection1.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE]

PARAMETER_NAME must match the name of the Parameter Field you put in your report.

Hope that helps
Luke
 
Back
Top