0

我有一个在 VB 2010 项目中使用的数据库。我所做的是删除了一个数据库字段的文本框,我将它拖到表单上,并将其替换为一个组合框。字段名称是orderstatus

问题是这样的:由于我从表单中删除了文本框字段,我似乎无法将组合框值绑定到活动记录中的字段。换句话说,orderstatus文本框不再存在。我想让用户从组合框中选择一个状态并将该值存储到 orderstatus 以便将其保存到我的数据库的当前记录中。

我想做这样的事情:

Private Sub Button16_Click_1(sender As System.Object, e As System.EventArgs) Handles Button16.Click
  orderstatus = ComboBox13.SelectedValue
  Me.OrdersDataSet.orders(0).orderstatus = orderstatus
  Me.Validate()
  Me.OrdersBindingSource.EndEdit()
  Me.TableAdapterManager12.UpdateAll(Me.OrdersDataSet)
End Sub

但它不喜欢我尝试将值分配给字段的第二行,说没有第 0 行。我要做的就是将组合框的选定值放入正在创建的记录的 orderstatus 字段中(或更新)。

我也尝试过使用:

Me.OrdersDataSet.orders.orderstatusColumn = orderstatus

我收到一条消息,说该列的属性是只读的。我不确定这怎么可能,因为我将数据集配置为更新等。

我可能应该提一下,我没有使用 datagridview 而是使用详细信息视图,如果这会有所不同的话。我已经看到一些关于如何使用 datagridview 执行此操作的讨论,但不知道这是否适用于我的情况。

我究竟做错了什么?我应该用什么来只更新当前行中我想要的列?

4

1 回答 1

0

Ugh, turns out I had forgot to set the databinding properties of the field in question to save directly to the binding source and also select the selecteditem to bind. It was right there and I didn't realize. Ya live and learn. :)

于 2013-02-08T19:22:10.470 回答