Menu

Comparing, Null, DBNull

simonl
2005-09-09
2013-03-07
  • simonl

    simonl - 2005-09-09

    Hi all

    Coming along nicely. Here's a little one though. If I bind my ObjectView into a DataGrid and try and sort when the column contains mostly strings but also some nulls out of NHibernate we get exceptions.

    The traps for nulls on lines 44 and 48 of ObjectViewComparer.cs don't trap System.DBNulls coming in.

    Is there something else I should know, or is the 'proper' fix to change these lines to read like:
      if (xValue == null || xValue is DBNull)
      {
        xValue = String.Empty;
      }
      if (yValue == null || yValue is DBNull)
      {
        yValue = String.Empty;
      }

    Keep up the good work!

     
    • Martijn Boland

      Martijn Boland - 2005-09-09

      Allright! Forgot about those DBNulls coming in. The way you handled these looks fine.

       
    • Donald L Mull Jr.

      You request is reasonable, but I'm confused. A string can't be DBNull, only null or a string. Is it an object that just usually holds a string?

       
    • simonl

      simonl - 2005-09-10

      Yeah, okay luggage :-)

      My NHibernate map for the field in question is for a string to an nvarchar in SQL Server. I thort that would mean I'd get strings, but instead this DBNull comes out of nowhere when I click the sort header in a datagrid bound to that view.

      In the ICompare implementation it's getting objects which aren't empty strings - they're DBNulls.

      Oh well...

       
    • Martijn Boland

      Martijn Boland - 2005-09-10

      The DBNulls probably come from the DataGrid. It thinks that [null] means DBNull.

       
    • Donald L Mull Jr.

      Gotcha. I use mostly Infragistics controls in my projects at work, so I am unfamiliar with the behavior of the DataGrid.

       
    • Martijn Boland

      Martijn Boland - 2005-09-12

      I thought Infragistics controls do the same when you allow null values, but I'm not entirely sure.

       
    • Donald L Mull Jr.

       

Log in to post a comment.

MongoDB Logo MongoDB