无法将属性绑定到列

时间:2012-06-12 13:26:49

标签: vb.net datasource

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

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

我在另一个具有不同查询的文本框中执行此操作(相同的代码,只是将列名称从“收件人”更改为“发布者”)只是为了调试而且它有效!我再次尝试了“接收者”,但它仍然无法正常工作。 我的代码:

    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()

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

1 个答案:

答案 0 :(得分:0)

我认为你应该写

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

从您的查询返回的列称为RecipientSNo
DataBindings.Add使用ReceipientSNo