cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

pass it as a string[]

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

rptDoc.SetParameterValue("FirstName", values);

Answers (2)

Answers (2)

Former Member
0 Kudos

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)

Former Member
0 Kudos

Hi,

replace your code from above with this:


Dim paramValue As CrystalDecisions.Shared.ParameterDiscreteValue

Dim pField As CrystalDecisions.Shared.ParameterField
pField = crReportDocument.ParameterFields.Item("TG")

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)

Bye

former_member183750
Active Contributor
0 Kudos

There is also a number of sample apps here:

https://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsfor.NETSDK+Samples

A code walk through article here;

http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/2081b4d9-6864-2b10-f49d-918baefc7a23

and finally, don't forget the developer help files:

http://boc.sdn.sap.com/developer/library

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Former Member
0 Kudos

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