0

我使用 vb.net 2008,我想将 txtEmpNo 绑定到 txtRate。但我检查了专栏是正确的。

错误“无法绑定到 DataSource 上的属性或列 Rate。参数名称:dataMember”

此代码:

Private Sub txtEmpNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmpNo.KeyPress
        Dim da3 As New SqlDataAdapter
        Dim ds3 As New DataSet()

        Dim sqlRate As String = "SELECT Max(Rate) From EmployeeSalary WHERE EmployeeRun = '" & txtEmpNo.Text.ToString & "'"
        da3 = New SqlDataAdapter(sqlRate, Conn)
        da3.Fill(ds3, "EmployeeRun")
        If ds3.Tables("EmployeeRun").Rows.Count > 0 Then
            txtRate.DataBindings.Add(New Binding("Text", ds3.Tables("EmployeeRun"), "Rate"))
            txtRate.DataBindings.Clear()
        Else
            txtRate.Text = ""
        End If
    End Sub

谢谢你的时间。:)

4

1 回答 1

0

请检查您的查询,将费率别名设置为max(rate)

改变:

 Dim sqlRate As String = "SELECT Max(Rate) From EmployeeSalary WHERE EmployeeRun = '" & txtEmpNo.Text.ToString & "'"

如果您执行此查询,结果将是

|(No ColumnName)|
| max rate value|

 Dim sqlRate As String = "SELECT Max(Rate) as Rate From EmployeeSalary WHERE EmployeeRun = '" & txtEmpNo.Text.ToString & "'"

这将显示

|Rate           |
|max rate value |

最好的祝福

于 2013-03-07T03:36:44.493 回答