Null value confusion RRS feed

  • Question

  • I have a data adapter that was created from a stored procedure which returns two string values.  One or both may be null, so I set the NullValue property to (Empty) for both -- the other choices are (Null) and (Throw Exception).


    I thought this would mean that it would convert any null value to an empty string.  However, when I ran my application and there was a null value in the database, it threw an exception when I attempted to assign the value to a string.


    So it did not work as I expected; I had to explicitly check for a null value before I did the assignment.


    My question is:  what is the NullValue property for, if not to tell the dataset adapter what to do when it encounters a DbNull value in the database?

    Wednesday, May 21, 2008 4:35 PM

All replies

  • I don't have an answer but my question is similar.  How do you handle null values without having to check every case?   If there is not a way to do this at the data layer level (I am using entity framework), how can you do it in LINQ?  Is there an equivalent to NVL, IFNULL or COALESCE?  Maybe someone can answer both of usSmile

    Thursday, May 22, 2008 8:59 PM
  • I usually check to see if the value is null.  However, if I don't want to check to see if the value is null, then I will write the SQL statement with an

    isnull(fieldname, '') as fieldname

    - this will return an empty string in place of the null and you won't get the exceptions.  Then you just have to know that the empty string is the same as if the field was null.  You might have problems later when updating the dataset this way because the value in the dataset will be an empty string and not null, so if you update the row it won't be a null anymore unless you check to see if the value is an emtpy string and then set the parameter on the update to null.  I hope that makes sense.


    Wednesday, October 8, 2008 4:14 PM