Thanks for the tips from 26-Jul-2003. For several days now I have been looking for how to pass Crystal runtime parameters based on web controls. I was able to apply your C# example to VB
.NET and successfully use the param in my report. Here are the steps I followed:
I created a Crystal Report using any old data source. Then I created a string parameter called MyParameter. After that I created a new WebForm with a textbox, button and CrystalReportViewer controls. Run the form, enter something in the textbox, click the button, and voilà!
Here's the code for the onclick event of the button (in VB
Dim crParamField As New ParameterField
Dim crParamFields As New ParameterFields
Dim crParamValue As ParameterValue
Dim crParamValues As New ParameterValues
Dim crReport As New CrystalReport1
Dim crParamDiscreteValue As New ParameterDiscreteValue
CrystalReportViewer1.ReportSource = crReport
crParamFields = CrystalReportViewer1.ParameterFieldInfo
crParamField = crParamFields("MyParameter")
crParamValues = crParamField.CurrentValues
crParamDiscreteValue.Value = Me.TextBox1.Text
I also tried hard-coding the databinding of the report source in the webform and that worked too, except then you'd need to remove Dim crReport As New CrystalReport1 and CrystalReportViewer1.ReportSource = crReport and use CrystalReportViewer1.DataBind() on the first line after the Dim statements.
I'm new to CR, and let me tell you, I found this whole exercise frustrating to no end. Sure, CR is very powerful, but this is needlessly complicated. Eleven lines of code to pass-in a parameter seems excessive. And there are no resources online (believe me, I searched and searched and read and read) that explain how to do this.
IMHO, CR gets off easy by being included in VS2003. MS should consider pushing CrystalDecisions to revamp their product. It shouldn't be this complicated to do basic stuff. For example, try making a report using a Wizard. Name the report something. Then try to rename the report. I gave up trying to find where this value is stored. It should be much less of a headache for developers to use this otherwise fine product.
I'd appreciate any comments you might have: email@example.com