0

我到处搜索,找不到答案。每个示例要么有一个数据网格视图,要么在 Select 处停止。我需要将 DataContext 结果作为变量存储在 VB 中。在前面的代码中,我使用客户姓名的下拉列表填充 ComobBox。然后,当用户从组合框列表中选择客户名称时,我想:

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
4

1 回答 1

0

您应该具体化您的查询。

Me.PhoneTextBox.Text=dbPhone.Single();

当您调用 Single() 您的查询将调用 db 并从中获取值。

于 2013-04-14T05:49:28.393 回答