如何将Max Function Textbox1绑定到Textbox2?

时间:2013-03-07 03:33:16

标签: vb.net visual-studio-2008 data-binding binding textbox

我使用vb.net 2008,我希望将txtEmpNo绑定到txtRate。但我查了一下这是正确的。

错误“无法绑定到DataSource上的属性或列速率。参数名称: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

感谢您的时间。 :)

1 个答案:

答案 0 :(得分: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 |

最好的问候