我使用此代码从表中检索表记录,我想在单独的文本框中填充每个单元格数据,接下来我能做什么?
Dim match = From p In students_entities.StudentsInformations
Where p.ID = id
Select p
txtfirstName.text=????
如果你选择的id应该只有一个记录,所以你可以这样做
Dim match = (From p In students_entities.StudentsInformations
Where p.ID = id
Select p).FirstOrDefault
If match IsNot Nothing Then
txtfirstName.text= match.FirstName
End If
或
Dim match = students_entities.StudentsInformations.FirstOrDefault(Function(f) f.ID = id)
If match IsNot Nothing Then
txtfirstName.text= match.FirstName
End If
您应该告诉EF您需要第一行。使用FirstOrDefault或Single函数。
Dim match = From p In students_entities.StudentsInformations
Where p.ID = id
Select p
txtfirstName.text= match.FirstOrDefault().name