This method may be useful for what you are trying to do. It will try to parse the column value in the corresponding type, and if it fails, it will return the default values for the types.
public T ParseValue<T>(System.Data.SqlClient.SqlDataReader reader, string column)
{
T result = default(T);
int index = reader.GetOrdinal(column);
if (!reader.IsDBNull(index))
result = (T)reader.GetValue(index);
return result;
}
source
share