|
-
Aug 16th, 2006, 03:24 PM
#1
Thread Starter
Hyperactive Member
[2.0] nullable modifier??
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");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|