Search code examples
c#asp.net-mvcvisual-studio-2008datasetdbnull

DBNull values on an ASP.NET MVC view


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.


Solution

  • 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