我到处搜索,找不到答案。每个示例都有一个datagridview或在Select处停止。我需要将DataContext结果存储为VB中的变量。在前面的代码中,我使用下拉列表中的客户名称填充ComobBox。然后,当用户从Combbox列表中选择客户名称时,我想:
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim dbmanex As New Manex_LINQDataContext
Dim dbPhone = From c In dbmanex.CUSTOMERs
Where c.CUSTNAME = Me.ComboBox1.Text
Select c.PHONE
Me.PhoneTextBox.Text = dbPhone
End Sub
PhoneTextBox.Text只是空白。任何见解将不胜感激。
Kirill Bestemyanov解决:
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim dbmanex As New Manex_LINQDataContext
Dim dbPhone = From c In dbmanex.CUSTOMERs
Select c.PHONE
Me.PhoneTextBox.Text = dbPhone.Single()
End Sub
答案 0 :(得分:0)
您应该具体化您的查询。
Me.PhoneTextBox.Text=dbPhone.Single();
当您调用Single()时,您的查询将调用db并从中获取值。