Click here to Skip to main content
Rate this: bad
good
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 Ab564
Edited 6-Sep-12 6:35am
v4
Comments
dimpledevani at 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 at 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
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 CPallini 170
4 _Amy 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 Sergey Alexandrovich Kryukov 154


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
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