This is a migrated thread and some comments may be shown as answers.

Filter Descriptor on Nullable fields

7 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 24 Sep 2010, 02:36 PM
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;

           }
       }


7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 28 Sep 2010, 12:28 PM
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
0
Peter Huisman
Top achievements
Rank 2
answered on 10 Jan 2011, 11:59 AM
Has this been followed up / solved?

I am getting the same error.
0
Rossen Hristov
Telerik team
answered on 11 Jan 2011, 11:30 AM
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>>
0
Bastien
Top achievements
Rank 1
answered on 27 May 2011, 03:44 PM
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);
0
Bastien
Top achievements
Rank 1
answered on 30 May 2011, 08:11 AM
no workaround yet?
0
Rossen Hristov
Telerik team
answered on 30 May 2011, 08:40 AM
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
0
Steven
Top achievements
Rank 1
answered on 15 Sep 2011, 11:56 AM
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
Tags
GridView
Asked by
Tony
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Peter Huisman
Top achievements
Rank 2
Bastien
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Share this question
or