Filter Descriptor on Nullable fields

8 posts, 0 answers
  1. Tony
    Tony avatar
    6 posts
    Member since:
    Sep 2008

    Posted 24 Sep 2010 Link to this post

    Using this  example as our template......
    http://demos.telerik.com/silverlight/#GridView/Search

    we are having an issue --- if the database field is defined as 'nullable' an exception is occurring

    on the line 

     convertedValue = Convert.ChangeType(FilterValue, descriptor.MemberType, CultureInfo.CurrentCulture);

    The exception is:
    cannot convert string to Nullable<Decimal>

    How do we fix this issue? (Entire function is listed below)
    Tony



    private void UpdateCompositeFilterValues()
           {
               foreach (FilterDescriptor descriptor in _compositeFilterDesriptor.FilterDescriptors)
               {
                   if (descriptor.MemberType == null) continue;

                   var convertedValue = DefaultValue(descriptor.MemberType);

                   try
                   {
                       convertedValue = Convert.ChangeType(FilterValue, descriptor.MemberType, CultureInfo.CurrentCulture);
                      ********************************************************************
                       Exception here: cannot convert string to Nullable<Decimal>
                        ********************************************************************************************************
                   }
                   catch (Exception e)
                   {
                       Logger.Error("CreateFilterExpression " + e.Message);
                   }

                   if (descriptor.MemberType.IsAssignableFrom(typeof(DateTime)))
                   {
                       DateTime date;
                       if (DateTime.TryParse(FilterValue, out date))
                       {
                           convertedValue = date;
                       }

                   }

                   descriptor.Value = convertedValue;

               }
           }


  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 28 Sep 2010 Link to this post

    Hello Tony,

    Could you please send us a runnable sample project that exhibits this behavior. This will save a lot of time.

    All the best,
    Ross
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Peter Huisman
    Peter Huisman avatar
    16 posts
    Member since:
    Dec 2004

    Posted 10 Jan 2011 Link to this post

    Has this been followed up / solved?

    I am getting the same error.
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 11 Jan 2011 Link to this post

    Hi Tony,

    You can add a check that if the string is null or empty you should assign null to the convertedValue variable. Maybe this will help. When do you get the exception, i.e. what are the values of all variables on the line where the exception is thrown? You can use the debugger, see their values and add the appropriate check.

    Greetings,
    Ross
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  6. Bastien
    Bastien avatar
    19 posts
    Member since:
    Mar 2010

    Posted 27 May 2011 Link to this post

    Same error... any solution found?

    I try to put something like that, but it doesn't work:
    if(descriptor.MemberType.Equals(typeof(string)))
        convertedValue = Convert.ChangeType(this.FilterValue, descriptor.MemberType, CultureInfo.CurrentCulture);
  7. Bastien
    Bastien avatar
    19 posts
    Member since:
    Mar 2010

    Posted 30 May 2011 Link to this post

    no workaround yet?
  8. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 30 May 2011 Link to this post

    Hi,

    Unfortunately, I cannot tell what is going on in your project, unless I have something that I can actually debug. 

    If you send me a small sample dummy project that exhibits the behavior you are faced with, I can take a look at it to see what is going on.

    Best wishes,

    Ross
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Steven
    Steven avatar
    35 posts
    Member since:
    Apr 2011

    Posted 15 Sep 2011 Link to this post

    Hi,

    Convert.ChangeType does not support Nullable thus you get an exception on your column of Nullable values.

    Does anyone have a fix?

    Regards,
    S
Back to Top
DevCraft banner