Click here to Skip to main content
13,088,464 members (55,042 online)
Rate this:
 
Please Sign up or sign in to vote.
I have a bit of code for adding parameter values to a report as below
     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 6-Sep-12 1:51am
Reji Ab605
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100