Question

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.

Was it helpful?

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

OTHER TIPS

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, ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top