I want to basically retrieve a value in a database table and assign it to a variable.
I declared the variable as nullable (basically I can assign a null value to the variable)

But it doesn't work. if the retrieved value has a null value I am not able to assign to the variable with nullable modifier. I get run time error saying "invalid cast" in the second line of the code.

while (oDataReader.Read())
{


double? dAdvRateNullableType = (double)oDataReader[0];

if (dAdvRateNullableType.HasValue == true)
{
Console.WriteLine("there is value in the field and the value is " + (double)oDataReader[0]);
}
else
{
Console.WriteLine("there is no value in the field");
}

}