VB 6.0 - Set Parameter values to crystal report at runtime

Asked By Sharmilee Karunanidhi on 20-Nov-06 02:21 AM
    Hi,

I have created a parameter field in crystal report by setting database at design time. I want to pass value from windows application form.

im trying to pass values from vb.net form (from combobox). How to set the value selected from combo box to crystal report parameter.

i used

ReportDocument rpt = new ReportDocument();
rpt.Load("Crystalreport2.rpt");
rpt.SetParameterValue("Pid", combobox1.SelectedValue.ToString());

The error:

"Value does not fall within the expected range"

can anyone solve this.     


Solution:
ReportDocument rpt = new ReportDocument();
rpt.Load("CrystalReport2.rpt");
rpt.SetParamaterValue("Sid", combobox1.selectedvalue);
crystalreportviewer1.selectionformula = "{stu.sno}=" + convert.toint32(combobox1.selectedvalue);
crystalreportviewer1.reportsource = rpt;


Sushila Patel replied to Sharmilee Karunanidhi on 20-Nov-06 01:15 PM
Is the string >254 characters, the error occurs in such a case

Just an add-on to the above solution by Sushila Patel - sundar k replied to Sharmilee Karunanidhi on 24-Nov-06 01:59 AM

ReportDocument rpt = new ReportDocument();
rpt.Load("CrystalReport2.rpt");
rpt.SetParamaterValue("Sid", combobox1.selectedvalue);
crystalreportviewer1.selectionformula = "{stu.sno}=" + convert.toint32(combobox1.selectedvalue);
crystalreportviewer1.reportsource = rpt;

The above solution doesnt ideally solve the purpose of creating a "Parameter Variable Sid". I am not saying that this solution is incorrect. We can make this code fragment bit structured.

We can remove the highlighted(red) portion from the vb.net code and instead handle this particular piece in the CrystalReport2.rpt itself. Open the RPT file and goto,

Report-> Edit Selection Formula and the paste the below code,

{stu.sno}= {?pm-Sid}

Assuming Sid -> parameter varibale is already created in the RPT.

In the above vb.net code, Parameter variable Sid is already assigned with combobox1.selectedvalue, we need not re-assign this variable value to "Selection Formula" using Vb.net code.