views:

90

answers:

2

I am writing a simple ASP.NET MVC web app. At this point, I am just trying to display a strongly typed DataSet on the automatically generated view. However, some of the values in the DataSet are null and cause exceptions.

I am wondering how this simple scenario is handled by others. It seems excessive to sanitize all the values in the dataset and besides I am going to end up with a lot of datasets in the final product. I am using DataSets because I have an Oracle backend, so Entity models are kind of out - I'd rather not use sample providers or dish out money for a commercial solution.

If there is no easy solution for DataSets, that's fine. I just wanted to check before I plunge into some serious customization. I'd like to keep things as automated and conventional as possible.

Thanks in advance.

+1  A: 

Would it be out of the question to do something like:

<%= (eventClass["MyColumn"] != DBNull.Value) ? eventClass["MyColumn"] : "" %>

You could also convert that into a simple extension method to save space and keystrokes.

HTHs,
Charles

Charlino
Thanks, that was my first thought as well. It would not be out of the question, but it means I have to do that for every single field and my datasets have a lot of fields.
alexsome
+1  A: 

If you can modify your db, you could use the coalesce function to guarantee some non-null default value:

select coalesce(first_name, '') as first_name, ...

or

select coalesce(parent_id, 0) as parent_id, ...
Ray
Thanks for the suggestion, it's an interesting solution. I'll have to give it some thought.
alexsome