Friday, August 17, 2018

yet another way to sanity check a SqlParameter against DBNull in C#

double? foo = null;
SqlParameter fooParam = command.Parameters.Add("@Foo", SqlDbType.Float);
fooParam.Direction = ParameterDirection.Output;
if (foo.Value == DBNull.Value)
{
   foo = null;
}
else
{
   foo = ((double)(fooParam.Value));
}

No comments:

Post a Comment