Skip to content

Instantly share code, notes, and snippets.

@aleksandrzak-rafal
Created March 30, 2016 11:22
Show Gist options
  • Select an option

  • Save aleksandrzak-rafal/132215452189b0edf18139394aaac80d to your computer and use it in GitHub Desktop.

Select an option

Save aleksandrzak-rafal/132215452189b0edf18139394aaac80d to your computer and use it in GitHub Desktop.
Extension method for OdbcDataReader to get rid of null checking when calling Get functions.
public static T SafeGet<T>(this OdbcDataReader reader, int colIndex)
{
if (!reader.IsDBNull(colIndex))
{
return (T)reader.GetValue(colIndex);
}
else
{
return default(T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment