crystal reports

LostProgrammer

Well-known member
Joined
Jan 17, 2003
Messages
123
Using crystal reports with vs.net, I was trying to pass a couple of parameters to the report from code and then export the report to a pdf. Before trying to pass parameters everything worked fine. but now it throws and exception,"exception thrown by the target of invocation." and displays part of the report in the browser window with the parameter values i had passed. Does anyone know of a problem with exporting parameter fields to pdf? Im sure thats what is causing the problem.
Thanks for your help,


-lp
 
Can you throw your code out there so we can take a look? Ive done the exporting to PDF thing with .NET and Crystal and aside from some initial problems, its working just fine now. Perhaps looking through your code will clear things up.
 
rep = New VendorsRpt()
CrystalReportViewer1.ReportSource = rep
paramFields = CrystalReportViewer1.ParameterFieldInfo

paramStart = paramFields.Item("start")
paramValues = paramStart.CurrentValues

paramValue = New CrystalDecisions.Shared.ParameterDiscreteValue()

paramValue.Value = "start"
paramValues.Add(paramValue)
paramStart.CurrentValues = paramValues
CrystalReportViewer1.ParameterFieldInfo = paramFields

... then the usual export code.
again, the export was working fine without the params so, i dont think thats it.
any help is appreciated.

-lp
 
So looking at your code, it looks like youre passing the report to the Crystal Viewer as well. Is there a reason youre doing that? To prevent having you look through LOTS of code at this point, these are my basic steps to making this work for my project:

** Load the report
** Set the parameters and add the current values to the report document itself: (rptDoc.DataDefinition.ParameterFields("myParam").AddCurrentValues(myparameterValuesCollection)
** Log into the table(s) used by the report document object
** Run the export code, without using the Crystal Viewer

Since Im doing the export, theres no need to use the viewer. If you want the report to show in the browser window, you can simply use:

Response.ClearContent()
Response.ClearHeaders()
Select Case exportType
Case "PDF"
Response.ContentType = "application/pdf"
Case "EXCEL"
Response.ContentType = "application/vnd.ms-excel"
End Select
Response.WriteFile(exportFile)
Response.Flush()
Response.Close()

Delete the exported file from the hard disk
System.IO.File.Delete(exportFile)

The "Response.WriteFile(exportFile)" will write the file to the hard disk of the computer and based on how the computer handles the file type, it will ask to either open or download the file. Hope this makes sense. Keep the questions coming - I remember how frustrating it was when I was trying to get Crystal to work some time ago in .NET. I hope I can save you some time and trouble. Good luck!
 
I just noticed the thing about the viewer. I dont really need it.
However I changed the code to the following and i am still getting the same exception ......aaarrrghhhhh

rep = New VendorRpt()
paramFields = rep.DataDefinition.ParameterFields


paramStart = paramFields.Item("start")
paramValues = paramStart.CurrentValues

paramValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
paramValue.Value = "1/1/99"
paramValues.Add(paramValue)
paramStart.ApplyCurrentValues(paramValues)

I went to the crystal support site, and it looked like the change from the viewer to the datadefinition should solve the problem.
of course it didnt. if you have any other ideas, please let me know.
thanks for your time,

-lp
 
HEY, I got it. For some reason i was refreshing the report before i exported it. For some other reason that seemed to cause the problem. Thanks for your help.

-lp
 
Back
Top