Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Crystal report pass parameter by programming Post Reply Post New Topic
Author Message
Naeem ul hassan
Newbie
Newbie


Joined: 21 Jul 2009
Location: Pakistan
Online Status: Offline
Posts: 1
Quote Naeem ul hassan Replybullet Topic: Crystal report pass parameter by programming
    Posted: 21 Jul 2009 at 5:38am
I am working on a Web Application in Asp.net 2.0. I want to pass parameter in crystal report by programming.

I write following code on button click but i am getting an Error:
"The types of the parameter field and parameter field current values are not compatible."

Currently i am passing one numeric parameter that has following detail:
Database Field Name = 'Emp_ID' and datatype is 'int'
Report Parameter name = 'EmpID' and data Type is numeric


CODE:
---------

Dim reportPath As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\NBX_Reporting\Testing.rpt"


Dim customerNumber As Integer = CInt(TextBox3.Text.Trim())

Dim report As New ReportDocument()
report.Load(reportPath)

Dim parameterFieldDefinitions = report.DataDefinition.ParameterFields
Dim customerNumberParameter = parameterFieldDefinitions("EmpID")

Dim parameterValues = customerNumberParameter.CurrentValues

Dim discreteCustomerNumber = New ParameterDiscreteValue()


parameterValues.Add(discreteCustomerNumber)

customerNumberParameter.ApplyCurrentValues(parameterValues)

CrystalReportViewer1.SelectionFormula = "{NBX_Data.Orig_Ext} = {?EmpID}"
CrystalReportViewer1.ReportSource = report

CrystalReportViewer1.DataBind()
Naeem
IP IP Logged
shiresmith
Newbie
Newbie
Avatar

Joined: 20 Oct 2009
Online Status: Offline
Posts: 2
Quote shiresmith Replybullet Posted: 20 Oct 2009 at 6:33am
Hi There,
 
Although you place the value of your parameter in customerNumber, I can't see anywhere where you are then using it to actually set the parameter value in the report.
 
I use the SetParameterValue method to set parameters, e.g.:
 
MyReportDocument.SetParameterValue("MyParameterName", MyParameterValueObject)
 
So in your case, try the following:
 
report.SetParameterValue("EmpID",customerNumber)
 
to replace everything between "report.load(reportPath)" and CrystalReportViewer1.SelectionFormula=....."
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.