Hi,
I'm using a ReorderList to reorder items in a DataSet containing values that may be DBNull. However, whenever any of the values are DBNull, ReorderList.cs throws a "Failed to reorder" exception with the inner exception "Object cannot be cast from DBNull to other types."
Now, I think .NET is probably at fault for not understanding that DBNull really means the same thing as null here, but it's easier to fix this in ReorderList.cs. Just add the method:
private void ConvertDBNullToNull(IDictionary dict)
{
List<DictionaryEntry> nullEntries = new List<DictionaryEntry>();
foreach (DictionaryEntry entry in dict)
{
if (entry.Value is DBNull)
{
nullEntries.Add(entry);
}
}
foreach (DictionaryEntry entry in nullEntries)
{
dict[entry.Key] = null;
}
}
Then right before the call to dsv.Update near the end of DoReorderInternal, add :
ConvertDBNullToNull(values);
ConvertDBNullToNull(oldValues);
Have other people been able to reorder items from data tables with nullable columns, or is this just me?