Question: I'm trying to populate a class object with values from a database table. The `someObject.Property` field is a nullable int type.

```
someObject.Property = Convert.ToInt32(dbReader["SomeField"]);

```

So, if `SomeField` is `null`, `Convert` will give a `DBNull` error. Is there a specific method I should be using for this?

Answer: 
I use this, replacing `0` with whatever default. If the property is `nullable` then you would default to the C# `null`.

```
someObject.Property = (DBNull.Value.Equals(dbReader["SomeField"])) ? 0 : Convert.ToInt32(dbReader["SomeField"]);

```
There is `TryParse`

<http://msdn.microsoft.com/en-us/library/f02979c7.aspx>

You can also look at using the null coalescing operator `??` to give a default value if needed.