我有一个Access数据库连接到我的项目,我在这里尝试做的是在连接到datagridview上的字段的组合框中显示一些值。
这是我得到的错误
System.Data.EvaluateException: 'Cannot perform '=' operation on System.Int32 and System.String.'
这是代码
Private Sub form_inventory_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'InventoryManager2DataSet.Sub_Category' table. You can move, or remove it, as needed.
Me.Sub_CategoryTableAdapter.Fill(Me.InventoryManager2DataSet.Sub_Category)
'TODO: This line of code loads data into the 'InventoryManager2DataSet.Sub_Category' table. You can move, or remove it, as needed.
Me.Sub_CategoryTableAdapter.Fill(Me.InventoryManager2DataSet.Sub_Category)
'TODO: This line of code loads data into the 'InventoryManager2DataSet.Inventory' table. You can move, or remove it, as needed.
Me.InventoryTableAdapter.Fill(Me.InventoryManager2DataSet.Inventory)
Me.DataGridViewTextBoxColumn8.DisplayMember = "Category"
Me.DataGridViewTextBoxColumn8.ValueMember = "ID"
Me.DataGridViewTextBoxColumn8.DataSource = Sub_CategoryBindingSource
With Sub_CategoryComboBox
.DataSource = Sub_CategoryBindingSource
.DisplayMember = "Category"
.ValueMember = "Id"
End With
End Sub
Private Sub Sub_CategoryComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Sub_CategoryComboBox.SelectedIndexChanged
If Me.Sub_CategoryComboBox.SelectedIndex = -1 Then
InventoryBindingSource.Filter = Nothing
Else
InventoryBindingSource.Filter = $"convert[Sub Category] = '{Me.Sub_CategoryComboBox.SelectedValue}'"
End If
End Sub
此部分代码触发错误
InventoryBindingSource.Filter = $"convert[Sub Category] = '{Me.Sub_CategoryComboBox.SelectedValue}'"
我可以让它工作一个没有连接的干净的组合框,但是当它连接到现场时我无法使它工作。
Sub Category是Sub_Category Table中的一个查找字段,其中包含Category字段。
这里可视化:
答案 0 :(得分:0)
你说组合框的值是Id
属性
With Sub_CategoryComboBox
.DataSource = Sub_CategoryBindingSource
.DisplayMember = "Category"
.ValueMember = "Id" ' This line!
End With
然后你试图将组合框的值(Id
)与文本字段进行比较。
我现在不知道你的业务逻辑是什么,但我怀疑这可能就是你所需要的:
With Sub_CategoryComboBox
.DataSource = Sub_CategoryBindingSource
.DisplayMember = "Category"
.ValueMember = "Category" ' Changed!
End With