Wednesday, June 26, 2013

Fix to "Object must implement IConvertible" error when using objectdatasource withy multivalue parameter under Telerik Reports

If you want to pass multivalue parameters to an objectdatasource you have to make sure the argument type of the objectdatasource's method is object array. You cannot pass a List or array integer or etc.
In the method body convert the object [] to the needed array type  . You can do it this way:
parameter is:
(object[] eventTypes)
   
            int[] eventTypeIDs = eventTypes.Select( Convert.ToInt32).ToArray();

2 comments:

  1. No Big Coding on Conversion required :

    Two Points When using

    1. SQL Query in the Report
    use the following format for filtering based on parameter in the query
    Column IN (@Paramter)

    2. Calling StoreProc from Report
    In Configure Data Source when passing the parameter, pass it like this =AllValues(Parameters.Name.Value)

    This Solution works with Q3 Telrik Reporting Version 8.2.14.1204

    ReplyDelete
    Replies
    1. Two Points When using

      1. SQL Query in the Report
      use the following format for filtering based on parameter in the query
      Column IN (@Paramter)

      2. Calling StoreProc from Report
      In Configure Data Source when passing the parameter, pass it like this =AllValues(Parameters.Name.Value)

      This Solution works with Q3 Telrik Reporting Version 8.2.14.1204

      Also need to implement the following the following code in report class before the constructor call of the report
      public class AllValuesAggregateFunction : IAggregateFunction
      {
      ArrayList values;

      public void Accumulate(object[] values)
      {
      var value = values[0];
      this.values.Add(value);
      }

      public object GetValue()
      {
      return this.values;
      }

      public void Init()
      {
      this.values = new ArrayList();
      }

      public void Merge(IAggregateFunction aggregateFunction)
      {
      var otherFunction = (AllValuesAggregateFunction)aggregateFunction;
      this.values.AddRange(otherFunction.values);
      }
      }

      Delete