Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Redimensionate array of parametervalue

Back to Forum: Tech Off
  • User profile image
    levalencia

     

    Hello, in reporting services I have to pass parameters as an arry, the problem is that I dont know the number of parameters that the user is going to select because one of those parameters is a multivalue parameter,  So I used a constructor with a constant number   of 10 for example, then I iterate through the checkboxlist to know which checkboxes the user selected,  as I have 2 already know parameters, the number of parameters will be minimum 2 if the user doesnt select nothing on the checkboxlist, if the user selects 2 checkboxes list the parametervalue array will have 4 positions FILLED with data but the rest will be null, and I can send null parameters because I will have an error.

     

    ExecutionInfo execInfo;

    execInfo = rs.LoadReport(path, null);

    ReportParameter[] reportparameters=execInfo.Parameters;

    ParameterValue pNmEmpresa= new ParameterValue();

    pNmEmpresa.Name = "NmEmpresa";

    pNmEmpresa.Value = DropDownList1.SelectedValue;

    //reportparameters[0] = pNmEmpresa;

    ParameterValue pNmCiclo = new ParameterValue();

    pNmCiclo.Name = "NmCiclo";

    pNmCiclo.Value = DropDownList2.SelectedValue;

    //reportparameters[1] = pNmCiclo;

     

    ////rs.SetExecutionParameters();

    StringBuilder selectected = new StringBuilder();

    int TiposCompetenciasSeleccionadas = 0;

    ArrayList al = new ArrayList();

    for (int i = 0; i < CheckBoxList1.Items.Count; i++)

    {

    if (CheckBoxList1.ItemsIdea.Selected)

    {

    selectected.Append(CheckBoxList1.ItemsIdea.Value);

    selectected.Append(",");

    al.Add(CheckBoxList1.ItemsIdea.Value);

    TiposCompetenciasSeleccionadas++;

    }

    }

    ParameterValue[] parametros ;

    parametros = new ParameterValue[10];

    parametros[0] = pNmEmpresa;

    parametros[1] = pNmCiclo;

    //{ pNmEmpresa, pNmCiclo };

    //parametros.SetValue(

    for (int i = 0; i < al.Count; i++)

    {

    ParameterValue pNmTipoCompetencia = new ParameterValue();

    pNmTipoCompetencia.Name = "NmTipoCompetencia";

    pNmTipoCompetencia.Value = (string)alIdea;

    parametros[i + 2] = pNmTipoCompetencia;

    //parametros[i+2].Name ="NmTipoCompetencia";

    //parametros[i+2].Value = (string)al[1];

    }

    parametros.

    //string[] nmtiposcompetencia = selectected.ToString().Split(new char[] { ',' });

     

     

    rs.SetExecutionParameters(parametros, null);  ---> This is the line of the error


  • User profile image
    Yggdrasil

    levalencia wrote:
      So I used a constructor with a constant number   of 10 for example, then I iterate through the checkboxlist to know which checkboxes the user selected,


    The simplest way is to switch the order - first iterate through the checkboxlist and see how many you have (let's say 2), and then create the array with the calculated amount:



    // Returns two items.
    ArrayList checkedItems = GetItemsFromCheckBoxList();

    // 2 for the two constants
    ParameterValue[] parametros = new ParameterValue(checkedItems.count + 2);

  • User profile image
    lorad

    There are simple ways to do this. 2.0 allows you to do it without a cast.

    In .NET 2.0

    List<ParameterValue> parmList = new List<ParameterValue>();

    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
       if (CheckBoxListItems[i].Selected)
       {
          parmList.Add(CheckBoxList1.Items[i].Value);
       }
    }
    // ... other stuff as needed

    rs.SetExecutionParameters(parmList.ToArray(), null);


    In .NET 1.1

    ArrayList parmList = new ArrayList();

    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
       if (CheckBoxListItems[i].Selected)
       {
          parmList.Add(CheckBoxList1.Items[i].Value);
       }
    }
    // ... other stuff as needed

    rs.SetExecutionParameters((ParameterValue[])parmList.ToArray(), null);

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.