ReorderList throws exception when reordering items with DBNull columns

Last post 11-29-2006 2:33 PM by David Anson. 4 replies.

Sort Posts:

  • ReorderList throws exception when reordering items with DBNull columns

    06-23-2006, 2:23 AM
    • Member
      84 point Member
    • adunar
    • Member since 10-11-2005, 6:01 AM
    • Stanford, CA
    • Posts 18

    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?

  • Re: ReorderList throws exception when reordering items with DBNull columns

    07-21-2006, 2:15 AM
    • Member
      84 point Member
    • adunar
    • Member since 10-11-2005, 6:01 AM
    • Stanford, CA
    • Posts 18

    This bug is also in the June 26 release of the Atlas Control Toolkit.

    ...Anybody?

  • Re: ReorderList throws exception when reordering items with DBNull columns

    07-21-2006, 11:54 AM
    • Contributor
      4,346 point Contributor
    • sburke_msft
    • Member since 04-04-2006, 7:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam
    Sorry - never saw this post.  Looks like your fix is right.  I'll try it out and then check it in if so.
    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ReorderList throws exception when reordering items with DBNull columns

    11-23-2006, 11:53 PM
    • Member
      84 point Member
    • adunar
    • Member since 10-11-2005, 6:01 AM
    • Stanford, CA
    • Posts 18

    This bug is still in the 11/21/06 release of the toolkit. I've posted a fixed version of ReorderList.cs to CodePlex here:

    http://www.codeplex.com/WorkItem/View.aspx?ProjectName=AtlasControlToolkit&WorkItemId=5900

     Any chance this could be incorporated into the next toolkit release?

  • Re: ReorderList throws exception when reordering items with DBNull columns

    11-29-2006, 2:33 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-10-2006, 9:39 PM
    • Microsoft
    • Posts 1,842
    • AspNetTeam
    We'll have a look. Thanks for the reminder!!

    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (5 items)