Nullable object must have a value?

后端 未结 8 2417
旧时难觅i
旧时难觅i 2020-12-09 14:54

On the line: bool travel = fill.travel.Value; I am getting the following error:

Nullable object must have a value

a

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 14:58

    You can always switch to

     fill.travel.GetValueOrDefault()
    

    To provide the default (false), or the value of the boolean column from the database. Or you can specify the default with an overload. Either way, the nullable currently doesnt have a value, which is why you get that exception.

提交回复
热议问题