无法将“System.String”类型的对象强制转换为“System.Data.DataRowView”类型

时间:2013-11-15 01:10:34

标签: database vb.net data-binding combobox compiler-errors

我目前面临一个问题。我尝试使用resetbindings重置绑定源数据库中的模式,如下面的代码,最后弹出错误信息给我的一个组合框事件。

Me.IcvcmastBindingSource.DataSource = ""
Me.IcvcmastBindingSource.DataSource = qryview.AsDataView
Me.IcvcmastBindingSource.ResetBindings(True)

然后在我的组合框选择的索引更改事件的第一行显示错误消息(以粗体显示为Highligted)。

Private Sub ComboBox8_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox8.SelectedIndexChanged
    **Dim dtview As DataRowView = Me.IcvcmastBindingSource.Current**
    TextBox4.Text = dtview.Item("VCSTC1")
    TextBox5.Text = IIf(Me.ComboBox9.Text Is DBNull.Value, "N\A", Me.ComboBox9.Text)
    TextBox12.Text = dtview.Item("VCBUYP_1")
    TextBox9.Text = IIf(dtview.Item("VCUNID") Is DBNull.Value, "N\A", dtview.Item("VCUNID"))

End Sub

感谢任何人都可以帮助解决我的问题!!

通过以下方式修复:

通过添加Me.IcvcmastBindingSource.count来修复它,在执行resetbindingsource为true之后,它会将count返回为0.

Private Sub ComboBox8_SelectedIndexChanged(ByVal sender As Object, ByVal e As    System.EventArgs) Handles ComboBox8.SelectedIndexChanged

If  Not Me.IcvcmastBindingSource.count = 0 then
Dim dtview As DataRowView = Me.IcvcmastBindingSource.Current
TextBox4.Text = dtview.Item("VCSTC1")
TextBox5.Text = IIf(Me.ComboBox9.Text Is DBNull.Value, "N\A", Me.ComboBox9.Text)
TextBox12.Text = dtview.Item("VCBUYP_1")
TextBox9.Text = IIf(dtview.Item("VCUNID") Is DBNull.Value, "N\A", dtview.Item("VCUNID"))

else

exit sub
end If

0 个答案:

没有答案