1

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

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

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

4

1 回答 1

0

我认为你应该写

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

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

于 2012-06-12T13:47:47.663 回答