Skip to Content
avatar image
Former Member

How to pass multiple values to a parameter from .Net Application

Hello - I am customizing a .NET application ou tof box a third party tool. I have created a crystal 2008 report with a parameter for multiple values and it works from crystal report. I can pass discrete value as shown below, how can I make it to pass multiple values like, "ANSTG","TMTG",...

Dim paramValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()

paramValue.Value = "ANSTG"

crReportDocument.SetParameterValue("TG", paramValue)

When I Pass paramValu.Valu = "ANSTG","TMTG", report opens with no data.

what is the correct way of pasing multiple values?

Thanks for the help.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 13, 2010 at 08:56 PM

    I just recently faced this issue. What you want to do is build a list of string (or int for numbers, or datetime for datetimes or whatever is your crystal parameter's data type). Populate the array, then pass it to the SetParameterValue() funciton. This is my code...pay no attention to my own internal structures. The interesting variable is string [] values

                  string[] values = new string[(HdlParam.WpfUIParameterElements.First() as ListView).SelectedItems.Count];
                  int i = 0;
                  foreach (HdLParameterValueAndDescription HdLElem in (HdlParam.WpfUIParameterElements.First() as ListView).SelectedItems)
                  {
                    values<i> = HdLElem.Value.ToString();
                    i++;
                  }
    
                  ReportCopy.SetParameterValue(HdlParam.crystalParamName, values);
    

    I hope it helps

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      pass it as a string[]

      string[] values = {"Mark", "Jason"};

      rptDoc.SetParameterValue("FirstName", values);

  • avatar image
    Former Member
    Mar 19, 2010 at 09:20 AM

    Hi,

    I think you can do it like this:

    C# Code:

    ParameterField pField = crReportDocument.ParameterFields["TG"];
    pField.CurrentValues.Clear()
    
    ParameterDiscreteValue pDisVal;
    
    pDisVal = new ParameterDiscreteValue();
    pDisVal.Value = "ANSTG";
    pField.CurrentValues.Add(pDisVal);
    
    pDisVal = new ParameterDiscreteValue();
    pDisVal.Value = "ANSTG";
    pField.CurrentValues.Add(pDisVal);
    
    ...
    

    Good luck

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 19, 2010 at 07:31 PM

    Thanks for reply, I modified my code per last reply as follows. I am doing in VB.net.It works fine when I pass single value but generates error for more than one value - "Value does not fall within the expected range". In crystal report parameter is set up as Dynamic, string, Multiple values and not range based. What am I doing wrong?

    Dim paramValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()

    Dim pField As New CrystalDecisions.Shared.ParameterField

    pField = New CrystalDecisions.Shared.ParameterField

    pField.Name = "TG"

    Dim pFields As New CrystalDecisions.Shared.ParameterFields

    pFields = New CrystalDecisions.Shared.ParameterFields

    pFields.Add(pField)

    pField.CurrentValues.clear()

    ParamValue= New CrystalDecisions.Shared.ParameterDiscreteValue()

    paramValue.Value = "TMTG"

    pField.CurrentValues.Add(ParamValue)

    ParamValue=New CrystalDecisions.Shared.ParameterDiscreteValue()

    paramValue.Value = "ANSTG"

    pField.CurrentValues.Add(ParamValue)

    crReportDocument.SetParameterValue("TG", pField)

    Add comment
    10|10000 characters needed characters exceeded