Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a bit of code for adding parameter values to a report as below
VB
Dim pFields As New ParameterFields()
 Dim pField As New ParameterField()
  Dim disVal As New ParameterDiscreteValue()
  Dim rptDoc As New ReportDocument()

   pField.ParameterFieldName ="ToDate"
       disVal.Value = frmReport.DTPTo.Value
       pField.CurrentValues.Add(disVal)
       pFields.Add(pField)

       pField.ParameterFieldName = "FromDate"
       disVal.Value = frmReport.DTPFrom.Value
       pField.CurrentValues.Add(disVal)
       pFields.Add(pField)

CrystalReportViewer1.ParameterFieldInfo = pFields

The problem is when I run the code report only gets last parameter "fromdate" only. It still ask me to enter "todate" manually. I defined "fromdate" and "todate" as date type in the report. Its only getting the last parameter I send

Anybody has got any ideas.
Posted
Updated 6-Sep-12 6:35am
v4
Comments
dimpledevani 7-Sep-12 5:06am    
Thats because you are over riding the Parameter field value.For each parameter you should have different ParameterField fields.e.g
pField1.ParameterFieldName = "FromDate"
disVal.Value = frmReport.DTPFrom.Value
pField1.CurrentValues.Add(disVal)
pFields.Add(pField1)

pField2.ParameterFieldName = "FromDate"
disVal.Value = frmReport.DTPFrom.Value
pField2.CurrentValues.Add(disVal)
pFields.Add(pField2)

1 solution

Hi Reji Ab,

Please Try this.
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//Set value for first parameter
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = frmReport.DTPTo.Value;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["ToDate"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
//Set value for second parameter
objParameterField = CrystalReportViewer1.ParameterFieldInfo["FromDate"];
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = frmReport.DTPFrom.Value;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
 
Share this answer
 
Comments
Reji Ab 7-Sep-12 7:05am    
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField) causing null value reference error. The other code works by instantiating both parameterfield and discretevalue for each parameter

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900