Specified Cast is not Valid (Crystal)

G

Guest

Since upgrading to .Net 2003, when I run report reports within an application
using CrystalReportViewer, I'm getting the error "Specified Cast is not
Valid". A value is being passed into the report.
 
B

Bernie Yaeger

Hi Andy,

How are you defining the parameter that you are passing into the report?
Let us see the code.

Bernie Yaeger
 
G

Guest

Hi Bernie

I have an opening form, the variable is populated by a combo box. I produce
the report by pressing a button to open the CrystalReportViewer. The report
is generated using a SQL Stored Procuedure.

Module module1

Public div As Integer

End Module


This is code I’ve input in the CrystalReportViewer

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

Dim parameterfields As CrystalDecisions.Shared.ParameterFields
Dim parameterfield As CrystalDecisions.Shared.ParameterField
Dim spvalue As CrystalDecisions.Shared.ParameterDiscreteValue
parameterfields = New CrystalDecisions.Shared.ParameterFields
parameterfield = New CrystalDecisions.Shared.ParameterField
parameterfield.ParameterFieldName = "@div"
spvalue = New CrystalDecisions.Shared.ParameterDiscreteValue
spvalue.Value = div
parameterfield.CurrentValues.Add(spvalue)
parameterfields.Add(parameterfield)
CrystalCountSheets.ParameterFieldInfo = parameterfields

Andy
 
B

Bernie Yaeger

OK; I've got the code - I'll be out of town a few days but I'll take a look
at it when I return.

Bernie
 
B

Bernie Yaeger

Hi Andy,

I could not duplicate your code in a test app because I do not know what
'crystalcountsheets' is.

Let's see if I can help another way. Here's how I pass parameters to a
crystal report through vb .net:
Dim paramFields As New ParameterFields

Dim paramField As New ParameterField

Dim paramField2 As New ParameterField

Case "f:\imcapps\histdeff.rpt"

paramField.ParameterFieldName = "pstartbox" ' the name of one parameter in
the report

paramField2.ParameterFieldName = "pendbox" ' the name of one parameter in
the report

discreteVal.Value = Me.mmcomment1

discreteVal2.Value = Me.mmcomment2

paramField.CurrentValues.Add(discreteVal)

paramField2.CurrentValues.Add(discreteVal2)

paramFields.Add(paramField)

paramFields.Add(paramField2)

CrystalReportViewer1.ParameterFieldInfo = paramFields

connectionchange()

I first assign the two parameter names in the report to a parameterfield
variable. I then assign values to discreteval and discreteval2. I then
make those the currentvalues of the parameter variables; then they are added
to the parameterfields collection; finally, I add the parameterfields
collection to the viewer's parameterfieldinfo. Connectionchange() simply
changes pwds, logins, etc and run the report document object.

HTH,

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top