Working with NULL fields in a Strongly Typed DataSet

This entry is here primarily because I have seen this question come up quite a few times. Perhaps when people Google, they will find this entry and avoid asking the question again.
With a strongly typed DataSet, a method is created on each field that can possibly come out of the database as a null. It is Is[Field}Null(). For example, if the field is named Title, the method is IsTitleNull(). So, if you would normally use the following code:
string title = ds.Employee[1].Title;
or similar, try this:
//You can set this up however you need to
//This is simply an example of one that has to display something
string title = String.Empty;
    title = ds.Employee[i].Title;
The other option is to edit the DataSet(s), but if you ever regen, you are hosed again. In other words, editing the DataSet is is kludge. Don’t do it. And, yes, I have seen it done … lots of times.
Peace and Grace,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: