Wednesday, February 26, 2014

LINQ NullReferenceException was unhandled


Public Class Form1
Dim db As CEEDataContext
Private Sub nptItem1A_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nptItem1E.CheckedChanged, nptItem1D.CheckedChanged, nptItem1C.CheckedChanged, nptItem1B.CheckedChanged, nptItem1A.CheckedChanged
Dim sItem1 As String = " "
If nptItem1A.Checked = True Then
sItem1 = "A"
ElseIf nptItem1B.Checked = True Then
sItem1 = "B"
ElseIf nptItem1C.Checked = True Then
sItem1 = "C"
ElseIf nptItem1D.Checked = True Then
sItem1 = "D"
ElseIf nptItem1E.Checked = True Then
sItem1 = "E"
End If

'mdiSLUCEE_CBT.CheckConnection()
giAppNo = 0
giAppNo = 2084567
Dim SearchAppNo = From encodedApp In db.tblCEE_Answers _
Where encodedApp.AppNo = giAppNo


If SearchAppNo.Count > 0 Then
SearchAppNo.First.AppNo = giAppNo
SearchAppNo.First.NumItem1 = sItem1
SearchAppNo.First.LastName = gsLastName
SearchAppNo.First.FirstName = gsFirstName
SearchAppNo.First.MiddleName = gsMiddleName
db.SubmitChanges()
Else
Dim newRecord As New tblCEE_Answer With _
{.AppNo = giAppNo, _
.LastName = gsLastName, _
.FirstName = gsFirstName, _
.MiddleName = gsMiddleName, _
.NumItem1 = sItem1}

db.tblCEE_Answers.InsertOnSubmit(newRecord)
db.SubmitChanges()
End If

End Sub
End Class


I'm getting error in this line



Dim SearchAppNo = From encodedApp In db.tblCEE_Answers _
Where encodedApp.AppNo = giAppNo



No comments:

Post a Comment