Nullable object must have a value?


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

Nullable object must have a value

and i am not sure why. All I want to do is get the value in the database of travel which is currently false. Any help would be appreciated.

using (var db = new DataClasses1DataContext())
    var fill = (from f in db.expenseHdrs
                where f.rptNo == getPkRowReport()
                select f).FirstOrDefault();

    txtReportDesc.Text = fill.description;
    txtPeriod.Text = fill.period;
    txtPurpose.Text = fill.purpose;

    bool travel =;
    chkTravel.Checked = travel 


You can always switch to

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.


Leave a Reply

Your email address will not be published. Required fields are marked *