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

GridView can't handle DBNull in dynamic data row

1 Answer 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Datafyer
Top achievements
Rank 1
Veteran
Datafyer asked on 25 Aug 2016, 10:57 PM

I am dynamically loading a small amount of data from a Sql Server table using the dynamic data row concept in this example.
Everything is working however if one of the values is DBNull then when the column is sorted the grid displays as blank. Toggling the sort back to off shows the data again.

To solve this I am simply casting to null when the value is DBNull.

var value = reader.GetValue(x);
                     
row[column] = value == DBNull.Value
    ? null
    : value;

 

This sounds to me like a bug.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Aug 2016, 02:02 PM
Hello Patrick,

The reported behavior is due to a LINQ exception caused by a type mismatch. Generally, when a DynamicObject is used, the data engine resolves the data type of a given property based on the data type of the relevant property of the first item. So, in this particular scenario, it tries to apply an object of type DBNull to a property of type String. Thus, an ArgumentException is raised and internally caught.

On the other hand, applying a null value to it a string property is a valid operation, thus the control is working as expected. I am afraid that there is not much we can do for this scenario, so I suggest you sticking to the approach you've already adopted.

All the best,
Stefan X1
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Datafyer
Top achievements
Rank 1
Veteran
Answers by
Stefan
Telerik team
Share this question
or