Tuesday, February 24, 2009

XSD & handling DBNull problem C#

The value for column xxx in table XXXXX is DBNull.
Recently, I started to use XSD for faster & easier object development in VS. One of obstacles which I discovered is DBNull which almost impossible to handle an exception via usual approach like . I posting this guide, because I saw many posts which propose non-trivial solutions.

I found two ways to make it easier:
1. To use try/catch mechanism, may result unnecessary slowness
2. The best: XSD class product for each object also a method for null/DBnull validation and by doing it helps to make a program in a very easy way.
Example: if objects name MyColumn so the method will be called IsMyColumnNameNull.

No comments: