Using the Npgsql module I'm running queries on a database. However, a number of the fields return null. This is how I'm currently handling it.
try
{
birthday = reader.GetString(2);
}
catch
{
birthday = "N/A";
}
This works okay and safeguards me in case of an exception being thrown. The problem is the GetString method is being ran often on values which are null, resulting in an exception being thrown. This little try/catch worked okay for an easy fix, but now I have many fields which may be null. If I want to assign a different value to my variable in the case when it is null, that means I have to create about 10+ of these little try/catch fixes to safely proceed......is there a better way I can go about this?