我正在尝试从 SQL Server 数据库中获取数据。
我的数据库中有一个名为的表Standard
。它具有三列StandardID
、StandardName
和Description
。
我有一个组合框,我在其中填写StandardName
这是代码:
Using db As New SchoolDBEntities
ComboSelectStandardToEdit.DataSource = db.Standards.ToList()
ComboSelectStandardToEdit.ValueMember = "StandardID"
ComboSelectStandardToEdit.DisplayMember = "StandardName"
End Using
现在我有 2 个名为txtStandardName
和的文本框txtDescription
。
我想根据StandardName
从组合框中选择的内容填充这两个文本框的值。
这是我尝试过的代码:
Using db As New SchoolDBEntities
Dim standard = From s In db.Standards
Where s.StandardId = CInt(ComboSelectStandardToEdit.SelectedValue)
Select s
txtStandardName.Text = CType(standard, Standard).StandardName
End Using
但不幸的是我得到了错误:
无法转换类型为“System.Data.Entity.Infrastructure.DbQuery”的对象
`1[EF_WinForms_VB.Standard]' to type 'EF_WinForms_VB.Standard'.