My original question was, as @nicholas correctly pointed, a little misleading, because this case is a little specific.
So here's the real problem:
I created Windows Form Application with DataGridView control and a DataSource generated from a table in my production database.
The goal of my program is to view the table, optionally edit comment columns and to export the table data to a XML file, which schema is strictly defined both with XSD and other independent constraints I cannot change.
It is especially important that I must not insert some fields into my XML output file if some values are not defined.
It's explicitly said I must not insert empty tags for those fields. That's the reason I need null values. To insert XML tags only where the value is given. That's why I need DBNull values, not any other default values.
The generated DataSet contains getters which throw an exception on accessing DBNull values. I cannot change generated code, it's a rule, you don't change generated code, especially the code which could (and would) be overwritten.
I solved this problem by surrounding each assignment of a nullable field with a "try/catch" block. If the generated getter throws an exception, my nullable field of my XML object will keep it's default null value, which is my expected behavior.
Later - my XML constructor will skip those fields while generating XML output.
But one problem remains: why does it have to be so ugly? What if I had a hundred nullable fields? Would I have to write a hundred "try/catch" blocks? It seems like a bug in the whole Microsoft mechanism to me. Or maybe there's a simple and elegant solution to this?
-- Here's the original content, to understand where the first answers came from:
Please, I do know I could check each field for DBNull, but there must be a automatic way for programmers. It would be the most stupid thing in whole .NET/C# - having to write "if" or "try/catch" statement for each column of my huge table! I've tried to use "foreach" on my table row type, but it didn't work. The exceptions are thrown at the very beginning of "foreach" body, it seems if I even try to touch DBNull, the exception is thrown. If I put my whole code block inside "try/catch" - it won't work because it will skip all fields behind first DBNull.
There must be a way to do it without putting a couple of dozens fugly checks in my code. So, what is the magic trick for the rows with DBNulls?