0

我的代码如下所示:

 Using dbContext as IRFEntities = New IRFEntities
 Dim getProspect = (From p in dbContext.IRF_Prospects _
                     where p.url = prospect_url _
                     Select p).FirstOrDefault
 If getProspect.user_id Is Nothing Then
                    ' Prepopulate the form with their information.
                    ' These must have a value, so we need to make sure that no column is null in the database.
                    ddlProgram.SelectedValue = getProspect.program
                    txtFirst.Text = getProspect.first_name
                    txtLast.Text = getProspect.last_name
                    txtAddress.Text = getProspect.address
                    txtCity.Text = getProspect.city
                    ddlState.SelectedValue = getProspect.state
                    txtZip.Text = getProspect.zip
                    txtPhone.Text = getProspect.phone
                    txtEmail.Text = getProspect.email_address
                    txtYearEnrolling.Text = getProspect.enrolling_in
                Else
                    ' Redirect them to login.
                    Response.Redirect("login.aspx")
                End If
   End Using

我收到以下错误:

System.InvalidOperationException 未被用户代码处理

H结果=-2146233079

Message=Nullable 对象必须有一个值。

在以下代码行:

txtYearEnrolling.Text = getProspect.enrolling_in

我知道为什么我会收到错误 - 数据库中的值为空。我想要做的是提取该值(如果存在),但如果不存在,我希望它采用默认值或将该字段留空。实现这一目标的最佳方法是什么?

4

0 回答 0