【问题标题】:Cannot bind the property to the column无法将属性绑定到列
【发布时间】:2012-06-15 09:29:51
【问题描述】:

我正在尝试在文本框中显示您选择的“收件人”的序列号,但出现此错误:

System.ArgumentException: Cannot bind to the property or column RecipientSNo on the DataSource.

我用不同的查询(相同的代码,只是将列名从'recipient'更改为'issuer')对另一个文本框执行此操作,只是为了调试并且它可以工作!我再次向“收件人”尝试了它,但它仍然不起作用;不起作用。 我的代码:

    query("SELECT RecipientSNo FROM Recipient WHERE CONCAT(FirstName, ' ', MI, '. ', LastName) = '" & ReceiverName.Text & "';")
    Try
        adapter = New MySqlDataAdapter(CommandText, ServerString)
        table = New DataTable
        Dim ds As New DataSet
        Dim bs As BindingSource
        adapter.Fill(ds, "recipient")
        bs = New BindingSource(ds, "recipient")
        DataBindings.Clear()
        ReceiverSNo.DataBindings.Add("text", bs, "ReceipientSNo")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
    disconnect()

这是来自“发行人”的有效代码:

    query("SELECT IssuerSNo FROM Issuer WHERE CONCAT(FirstName, ' ', MI, '. ', LastName) = '" & IssuerName.Text & "';")
    Try
        adapter = New MySqlDataAdapter(CommandText, ServerString)
        table = New DataTable
        Dim ds As New DataSet
        Dim bs As BindingSource
        adapter.Fill(ds, "armorer")
        bs = New BindingSource(ds, "armorer")
        IssuerSNo.DataBindings.Clear()
        IssuerSNo.DataBindings.Add("text", bs, "ArmorerSNo")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
    disconnect()

我刚刚处理了这段代码并更改了文本框和列名,但它已经不起作用了.. 似乎是什么问题?我已经仔细检查了我的表名和列名。

【问题讨论】:

    标签: vb.net datasource


    【解决方案1】:

    我觉得你应该写

    ReceiverSNo.DataBindings.Clear()         
    ReceiverSNo.DataBindings.Add("text", bs, "RecipientSNo") 
    

    查询返回的列名为RecipientSNo
    DataBindings.Add 使用ReceipientSNo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多