0

2008 年,我想将 txtEmpNo 绑定到 txtFullName。但我检查了专栏是正确的。

错误“无法绑定到数据源上的属性或列 [First Name]。参数名称:dataMember”

此代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim da3 As New SqlDataAdapter
            Dim ds3 As New DataSet()
            Dim bs2 As New BindingSource()

            Dim sql As String = "SELECT Employee.[First Name] From Employee WHERE Employee.EmployeeNo = '" & txtEmpNo.Text.ToString & "'"
            da3 = New SqlDataAdapter(sql, Conn)
            da3.Fill(ds3, "Employee")

            If ds3.Tables("Employee").Rows.Count > 0 Then
                txtFullName.DataBindings.Add(New Binding("Text", ds3, "Employee.[First Name]"))
                txtFullName.DataBindings.Clear()
            Else
                txtFullName.Text = ""
            End If
End Sub

谢谢你的时间。

4

1 回答 1

0

dataMember参数(第三个)应该只是列的名称。
DataSet 中的正确表应在第二个参数中传递。换句话说,将您的绑定更改为:

txtFullName.DataBindings.Add(New Binding("Text", ds3.Tables("Employee"), "First Name"))
于 2013-03-06T08:40:53.730 回答